In truth, the gospels were written anonymously. However, it was the uniform
decision by the early church who the books were written by:
The church was very unilateral in this decision of authorship - apparently, no
one disputed the decision.
It's not really questioned as to if these people wrote the books, since they
aren't exactly the most likely group - Mark and Luke weren't even disciples.
For example, if you look at the supposed authors of the apocryphal books,
they're much more prominent Bible characters such as Mary, Peter, Thomas,
James (John's brother, the disciple) and Philip.
Specifically relating to authorship, testimony from Papias in 125 AD confirms
Mark accurately recorderd Peter's experiences, and Irenaeus in 180 AD
confirmed all four gospels' authorship.
Matthew, Mark and Luke are known as synoptic gospels. This is because these
gospels are noticably similar in content. A mathematical comparison shows 91%
of Mark is found in Matthew, 53% of Mark is found in Luke. So the theory is
that Matthew and Luke drew from Mark's gospel in writing their own. This begs
the question:
Why would Matthew, a disciple of Jesus, base some of his gospel from Mark, who
wasn't even there?
James and John (brothers, sons of Zebedee) and Peter were closer to Jesus than
the other nine (such as at Gethsemane, the Transfiguration). Peter was
privy to events apart from the other nine, it isn't unreasonable that Matthew
would draw from Peter's observations, as recorded by Mark.
See also: Are the gospels reliable?