Skip to content

Instantly share code, notes, and snippets.

@coquer
Last active August 29, 2015 14:28
Show Gist options
  • Select an option

  • Save coquer/51c83ee846d8035f812c to your computer and use it in GitHub Desktop.

Select an option

Save coquer/51c83ee846d8035f812c to your computer and use it in GitHub Desktop.
Change default sender email address wordpress, This includes email being sent from a subdomains.
function setDefaultFromEmail(){
$url = "";
$parse = parse_url(home_url());
if (strpos($parse['host'], 'www') !== false) {
$url = preg_replace('#^www\.(.+\.)#i', '$1', $parse['host']);
}else{
$url = $parse['host'];
}
$array = explode(".", $url);
$uri = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : "").".".$array[count($array) - 1];
return "no-reply@" . $uri;
}
add_filter('wp_mail_from', 'setDefaultFromEmail');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment