It takes some detective work to parse out the information about the various Marys mentioned in the gospels. The episode you mention is particularly confusing because there are four different accounts with varied details in each of the four gospels.
Mark and Matthew both mention an unnamed woman who anoints Jesus’ head with either nard or ointment. Luke tells us of an unnamed woman “who was a sinner” who bathed Jesus’ feet with her tears, anointed them with ointment, and dried them with her hair. Then, to add even more confusion, John describes Mary of Bethany, aka Martha’s sister, anointing his feet with nard and wiping them with her hair. Only in John’s gospel is the woman named as Mary of Bethany.
That said, none of the accounts suggest any involvement by Mary Magdalene. If indeed there was a historical event of a woman anointing Jesus in a particularly extravagant way, we will simply never know who it was that enacted such a loving gesture for Jesus. Perhaps it was Mary, Martha’s sister, or perhaps it was done by another woman whose name has been lost to us forever.