There are obvious similarities between the two passages, to be sure, but there are also some key differences. Looking into the context of each passage helps to clarify the differences.
In John 6, Jesus gave his "I am the bread of life" speech both to the crowd whom he had fed miraculously just hours before, and to the "Jews," some of whom may have been with the crowd and some of whom were not part of the crowd but comprised a contingent of the Jewish leadership which was highly suspicious of Jesus and even plotted to kill Him (John 5:18). In the face of such unbelief and hostility, Jesus did not tone down his choice of words; rather, He ramped it up a notch!
In context, in encouraging people to eat His flesh and drink His blood Jesus was simply telling people to believe in Him and to accept Him for who He claimed to be, something the Jewish leadership was unwilling to do (John 5:39,40). Jesus was also aware the crowd which followed Him had mixed motives; in fact, Jesus suggested they followed Him from town to town because He had miraculously filled their bellies, a motive Jesus attempted to disabuse them of (John 6:26,27).
Later in John 6, Jesus explained the "hard saying" (His disciples' words) about eating flesh and drinking blood by telling them,
"It is the Spirit who gives life; the flesh profits nothing; the words that I have spoken to you are spirit and are life. But there are some of you who do not believe" (vv.63,64a).
Here Jesus is telling His disciples He was speaking spiritually, not literally. Again, the flesh and blood verbiage was a metaphor for belief in Him, and it was meant to expose the unbelief of the Jews.
When we turn over to Matthew 26:26, the context is very different indeed! In the Upper Room Discourse with His inner circle of disciples, Jesus enacted what was later called the Lord's Supper (communion, Eucharist, breaking of bread, mass). Aware that His life was nearing its end, Jesus took two common items in the traditional seder meal, unleavened bread and wine, and as His disciples ate and drank, Jesus called the bread His body and told them to eat it. He then called the wine His blood and told them to drink it. Henceforward, the New Covenant between God and believing humankind would be in Jesus' once and for all atoning sacrifice at Calvary, and not in the repeated atoning sacrifices of animals. Jesus, in other words, was truly the Paschal Lamb of God who bore away the sins of the world (John 1:29).
In conclusion, in Jesus' discourse to the crowd in John 6, He underscored the necessity of belief in Him and used the "flesh and blood" metaphor to hammer home the point about belief being the only means by which believers could have eternal life (v.58). In Jesus' Upper Room Discourse, He established an ordinance which has come down to us today through the centuries, as a way of reminding us both of His atoning sacrifice and of the commitment we made to Him when we believed and then entrusted our very lives to Him. By availing ourselves, by faith, of the forgiveness of sins we have through His broken body and spilled blood, we become the possessors of eternal life. In other words, in John 6, Jesus attempted to get people to believe, but in Matthew 26, He established an ordinance for all who have believed to "proclaim His death until He comes [back again]" (1 Corinthians 11:25,26).
"There is a fountain filled with blood
Drawn from Immanuel's veins,
And sinners plunged beneath that flood
Lose all their guilty stains.
The dying thief rejoiced to see
That fountain in his day;
And there may I, though vile as he,
Wash all my sins away.
Dear dying Lamb, thy precious blood
Shall never lose its power
Till all the ransomed church of God
Be saved, to sin no more.
(William Cowper, 1731-1800)