Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save espenmn/166fba5f763337e7f6d593c9ecfd5842 to your computer and use it in GitHub Desktop.

Select an option

Save espenmn/166fba5f763337e7f6d593c9ecfd5842 to your computer and use it in GitHub Desktop.
Example 1:
// Redirect to John Doe if mail body contains 'John Doe'
add_filter('wp_mail', 'medialog_john_doe', 99);
function medialog_john_doe($args)
{
if (str_contains($args['message'], 'John Doe')) {
$args['to'] = 'john@doe.com';
return $args;
}
}
Example 2:
// redirect 'foreign contacts' if email is 'from another country'
// alternative use 'does not end with', (str_ends_with($args['to'], '.com') == False
add_filter('wp_mail', 'medialog_foreign_redirect', 99);
function medialog_foreign_redirect($args)
{
if (str_ends_with($args['to'], '.com')) {
$args['to'] = 'foreigndepartment@company.com ';
return $args;
}
}
Example 3:
// Spam FILTER_VALIDATE_EMAIL
add_filter('wp_mail', 'medialog_mark_spam', 999);
function medialog_mark_spam($args)
{
if (str_contains($args['message'], 'some random text')) {
$args['subject'] = 'SPAM ';
return $args;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment