Complex sentence: The song was written by Sheeran while her girlfriend on her way to the airport to fly back home after a visit, and he wrote the song, recorded on his iPhone and sent it to her in an email.
Split into simpler sentences: The song was written by Sheeran while her girlfriend was on her way to the airport to fly back home after a visit. He wrote the song, recorded on his iPhone and sent it to her in an email.