Skip to content

Instantly share code, notes, and snippets.

@samin
Last active March 12, 2023 18:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samin/f89c0f9b67ae82200e22 to your computer and use it in GitHub Desktop.
Save samin/f89c0f9b67ae82200e22 to your computer and use it in GitHub Desktop.
function get_mx($email)
{
// Get domain name from email
$domain = substr(strrchr($email, "@"), 1);
// get MX records for domain
getmxrr($domain, $mxhosts);
// Match records with three options
preg_match('/google|hotmail|yahoo/i', implode(' ', $mxhosts), $matches);
// return option
return strtolower($matches[0]);
}
@danielapan
Copy link

danielapan commented May 25, 2016

Hello samin, awesome script. Just a thing: in this case it should be get_mx($email) instead of get_mx($domain)

@samin
Copy link
Author

samin commented May 28, 2018

@danielapan edited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment