Formal way to say you bumped into someone
Encountered is formal and fits. But you need to add an adjective to indicate that the meeting was unexpected:
“Yesterday I unexpectedly encountered John…”
or
“Yesterday, by chance, I encountered John…”
As a simpler alternative to the word, encounter, you could just use met, e.g.
“Yesterday, by chance, I met John…”
If you want a single word (albeit with a preposition), you could use the verb, chance:
“Yesterday I chanced into John…”
or with another verb:
“Yesterday I chanced to meet John…”
This is not informal, and although derived from a noun, is of some antiquity. The OED gives example from the sixteenth century, e.g.
“Chaunsynge into the company of them”
Although it describes it as “somewhat archaic”, the verb chance is in the (US) Merriam Webster dictionary:
to come or light by chance
they chanced upon a remote inn