Unable to prevent function using save_post firing twice

First, you can use this hook to target only one custom type: https://developer.wordpress.org/reference/hooks/save_post_post-post_type/ This hook (and save_post) is called the first time when you click on “new …” and then the hook is called with $update = FALSE. Then to send e-mail only when the object is updated, you can test $update like this: const … Read more

Multiple email recipient using wp_mail()

Yes it’s possible, $to accepts an array or comma-separated list of email addresses to send message. You can read more here, about optional headers parameter that can add from, cc, content-type, fields. If you want to send automaticaly WordPress admin notifications, you can have a look to this.

Check to check if wp_mail is working properly?

WordPress relies on the PHPMailer class to send email through PHP’s mail function. Since PHP’s mail function returns very little information after execution (only TRUE or FALSE), I suggest temporarily stripping down your mv_optin_mail function to a minimum in order to see if the wp_mail functions works. Example: $mailResult = false; $mailResult = wp_mail( ‘[email protected]’, … Read more

wp_mail and BCC headers

You could try to debug the output like this: function test_phpmailer_init( $phpmailer ) { echo ‘<pre>’; var_dump( $phpmailer ); echo ‘</pre>’; return $phpmailer; } add_action( ‘phpmailer_init’, ‘test_phpmailer_init’ ); The code in your question is correct, the problem is with your local SMTP application. If you are using a local SMTP server (e.x. Papercut), it only … Read more

How to send an email using wp_mail and using more than one BCC in the header

$headers can be a string or an array, but it may be easiest to use in the array form. To use it, push a string onto the array, starting with “From:”, “Bcc:” or “Cc:” (note the use of the “:”), followed by a valid email address. https://codex.wordpress.org/Function_Reference/wp_mail#Using_.24headers_To_Set_.22From:.22.2C_.22Cc:.22_and_.22Bcc:.22_Parameters In other words: $headers = array( ‘From: [email protected]’, … Read more

How to add headers to outgoing email?

Thanks to the above, I’ve realized my central mistake — I didn’t quite realize that the arguments being passed in were a multi-dimensional array. For now, I’ve re-implemented the function thus: function ws_add_site_header($email) { $email[‘headers’][] = ‘X-WU-Site: ‘ . parse_url(get_site_url(), PHP_URL_HOST) ; return $email; } My reading of the wp_mail() source (see: https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/pluggable.php#L235) leads me … Read more