Send automatic emails to multiple user roles when a custom field is updated in a custom post type

This code will allow you to call a custom function when your meta key is updated. add_action(‘updated_postmeta’,’my_meta_update’, 10, 4); function my_meta_update( $meta_id, $object_id, $meta_key, $meta_value ) { if($meta_key === ‘my_meta_key’) { // trigger email(s) // wp_mail( $to, $subject, $message, $headers, $attachments ); } } Like Shaun mentioned, you should always use an external email solution … Read more

How to use ‘phpmailer_init’ SMTP settings only on certain ‘wp_mail’ actions?

phpmailer_init will always fire for every wp_mail() call – however, you can hook/unhook it conditionally like so: function wpse_224496_phpmailer_init( $phpmailer ) { // SMTP setup // Always remove self at the end remove_action( ‘phpmailer_init’, __function__ ); } function wpse_224496_wp_mail( $mail ) { // Example: only SMTP for emails addressed to [email protected] if ( $mail[‘to’] === … Read more

Add multiple recipients via BCC on wp_mail()

You’d write them the same way you would any other email, the knowledge you need to do this is Email header knowledge, not WP knowledge. Those are raw email headers, and aren’t a special WP format. Since each item in the array is a line in the header of the email, we need to know … Read more

wp_mail line break not working

Modify the line that reads $headers .= ‘Content-type: text/html; charset=UTF-8’ . “\r\n”; to $headers .= ‘Content-Type: text/html; charset=ISO-8859-1″; and then use <br /> for the line breaks.

Email reply to multiple email addresses not working

Unfortunately this is not widely supported, not because WordPress does not support it, but because most email clients do not support it, so it cannot be relied upon. Instead, consider using a mailing list and use the mailing lists address as the reply to field

Using wp_mail() – verify that email was sent?

As you have probably found, for wp_mail(): A true return value does not automatically mean that the user received the email successfully. A possible workaround is to add an email address that you have access to in the recipients list, and if the one email address receives the mail you can be reasonably (although not … Read more

Adding an Attachment to Contact Form Using wp_mail

In short, I was simply failing to pass in the correct variable: if ( ! function_exists( ‘wp_handle_upload’ ) ) { require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); } $uploadedfile = $_FILES[‘uploaded_file’]; $upload_overrides = array( ‘test_form’ => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if( $movefile ) { //echo “File is valid, and was successfully uploaded.\n”; //var_dump( … 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.