Ancient ideas on "authorship" and "inspiration" might be different from ours.
A letter from Papias, the bishop of Hierapolis around the year 130, refers to Mark as being “Peter’s interpreter, who wrote down accurately, although not in order, all that he remembered of what the Lord had said or done.” St. Irenaeus and Clement of Alexandria support this identification, as they also support that of Luke as being the physician and beloved disciple of Paul (Colossians 4:14).
Matthew is identified with the tax collector Jesus calls as an apostle (Mt 9:9-13). Some sources claim it was Matthew who first compiled a collection of Jesus’ sayings in Aramaic, of which we only have the Greek version. John, on the other hand, was identified as John the Apostle by Irenaeus, following the instructions of his teacher, Polycarp, who was in turn a disciple of John himself.
But are Matthew, Mark, Luke, and John the authors of the Gospels? The answer depends on how we understand the notion of “authorship.”
The Dogmatic Constitution on Divine Revelation of the Second Vatican Council makes it clear that the Church “has firmly and with absolute constancy maintained and continues to maintain that the four Gospels, whose historicity she unhesitatingly affirms, faithfully hand on what Jesus, the Son of God, while He live among men, really did and taught for their eternal salvation until the day He was taken up.”
After Jesus’ Ascension the apostles, enlightened by the Holy Spirit and endowed with a fuller understanding of Jesus’ teachings, handed on to others what Jesus himself did and taught. These teachings and acts were written down by the sacred authors, also guided by the Holy Spirit themselves. They described and narrated the events and teachings of Jesus which they might have witnessed themselves, or which had been handed on to them, whether orally or in written form, sometimes synthesizing some of these teachings or events, or maybe adapting them for a specific audience (this being the main reason why the Gospels often describe the same things, but with different nuances).
But are these sacred authors also the saints we know as the Four Evangelists? To answer this question properly, there are at least two things we must keep in mind. The first one, that the Church has always referred to the Gospels as “according to”: we have the Gospel according to Matthew, according to Mark, according to Luke, and according to John (katá in the original Greek), not “by” any of these saints.
The second one, which follows from this, is that the ancient understanding of “authorship” was quite different from ours. In the ancient world, authorship might be attributed to the person who actually wrote the text, but also to the one who dictated the text to a scribe or a secretary. For example, we know Jeremiah dictated his words to a scribe named Baruch (Jeremiah 36:4), and Paul himself tells us it was a secretary called Tertius who wrote down his letter to the Romans (Romans 16:22). But also, an individual would still be considered the author of a text even if that person only provided the main ideas, or if the text was written according to that person’s thought, even if somebody else did the actual composition. In sum, a given individual was considered to be the author of a text if the work was written in that person’s tradition (as in the case of, for instance, David, who is considered the author of the Psalms, or Moses, who is credited with the first five books of the Bible).
It is hard to say whether the Gospels we have are indeed the handwritten work of any of these four saints. But regardless of who the inspired author was in the end, two things are clear: one, that the Gospels were indeed written in the very early days of Christianity — the earliest fragments of the Gospel of Matthew, for instance, have been dated in the year 40, thus indicating the author was indeed an eyewitness to Jesus’ public ministry — and, two, that these authors wrote what the Holy Spirit wanted them to write. As the Dogmatic Constitution on Divine Revelation reads, “since all that the inspired authors, or sacred writers, affirm should be regarded as affirmed by the Holy Spirit, we must acknowledge that the books of Sacred Scripture firmly, faithfully and without error, teach that truth, which God, for the sake of our salvation, wished to see confided to the Sacred Scriptures.”