In order to win the jackpot, which starts at a minimum of $20 million and increases each time it rolls over, participants must match all five numbers and the Mega Ball. Mega Millions players are required to select five main numbers between 1 and 70 and one Mega Ball from a pool of 1 to 25. Both styles of company are heavily regulated to make sure they will pay out, so your entry money is safe. So no ticket is physically purchased but you will be paid out the same as if you had actually bought the ticket (the betting companies take out expensive insurance with providers Lloyds of London to cover the eventuality of somebody winning). Others will take a 'bet' from you against that lottery. That ticket will then be scanned and put into your account online so you can see that it has been bought.
Some use a concierge service where a person in the USA will go out and physically buy your ticket for you. There are a number of providers on the Internet who allow you to play MegaMillions from the UK.
Play Online Now Can I play MegaMillions in the UK