Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save WProbot/75604b6dcd5bf50be29f8b9bd46e1af6 to your computer and use it in GitHub Desktop.

Select an option

Save WProbot/75604b6dcd5bf50be29f8b9bd46e1af6 to your computer and use it in GitHub Desktop.
Change the wp_mail() "to" address based on subject
<?php
/**
* This is a filter for wp_mail(). It checks the subject
* for the presence of a given string (in this case "New
* User Registration"), and if that returns true it
* sets the "to" address/value.
*/
add_filter( 'wp_mail', 'my_wp_mail_filter' );
function my_wp_mail_filter( $args ) {
// Check the message subject for a known string in the notification email.
if ( strpos( $args['subject'], 'New User Registration' ) ) {
// This is the notification email, so change the "to" address.
$args['to'] = 'alternate@example.com';
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment