From Mega millions website FAQ
Can I buy Mega Millions tickets if I live in another country?
Visitors to the United States are always welcome to purchase tickets for our game from an American lottery retailer while they are visiting this country; you do not need to be a resident to win. Mega Millions is not affiliated with and does not endorse any company claiming to sell our tickets around the world, online or otherwise. If you choose to do business with one of these companies, you do so at your own risk.