Do something after sending email

Using the PHPMailer class with an action callback: I did some digging into the PHPMailer class and found that it supports a custom action. Here’s how the callback is activated with the doCallback() method in the class. There’s also a PHPMailer test on GitHub using this feature via the callbackAction() callback. We can set it … Read more

Using wp_mail with attachments but no attachments received

The $attachment argument for wp_mail takes a file (or array of files) – but the file path has to be fully specified. For example: <?php $attachments = array(WP_CONTENT_DIR . ‘/uploads/file_to_attach.zip’); $headers=”From: My Name <[email protected]>” . “\r\n”; wp_mail(‘[email protected]’, ‘subject’, ‘message’, $headers, $attachments); ?> (see Codex). It seems that your $_POST[‘file’] is probably not specifying the full … Read more

What is the advantage of using wp_mail?

wp_mail() is a pluggable function: It can be replaced by plugins. That’s useful in cases where the regular mail() doesn’t work (good enough), for example when you need extra authentication details. Example: WP Mail SMTP wp_mail() uses PHPMailer by default, a sophisticated PHP class which offers a lot of useful preprocessing and workarounds for cases … Read more

Why won’t wp_mail() let me set the From: header when plain old PHP mail() will?

Hi @helenyhou: You can set the header, just not with a parameter. WordPress uses “hooks” and the hooks you need are ‘wp_mail_from’ and ‘wp_mail_from_name’ hooks. Here are the hooks you might add to your theme’s functions.php file to modify the “From:” header when using wp_mail() to the email address Helen Hou-Sandi <[email protected]>: add_filter(‘wp_mail_from’,’yoursite_wp_mail_from’); function yoursite_wp_mail_from($content_type) … Read more

Sending multipart (text/html) emails via wp_mail() will likely get your domain banned

The following version of wp_mail() is with the patch applied of @rmccue/@MattyRob in the ticket https://core.trac.wordpress.org/ticket/15448, refreshed for 4.2.2, which allows $message to be an array containing content-type keyed alternates: /** * Send mail, similar to PHP’s mail * * A true return value does not automatically mean that the user received the * email … Read more