Last active
March 1, 2023 08:55
-
-
Save espenmn/166fba5f763337e7f6d593c9ecfd5842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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