By default, e-mails sent from within a WordPress installation use the wp_mail() function (find it in wp-includes/pluggable.php), which in turn uses PHP’s mail() function. Therefore, e-mail is sent using whatever is configured for your server.

You can specify to WordPress that you want to use a particular SMTP server to send e-mail. Plugins such as the aptly named WP Mail SMTP enable you to specify this, including a username and password if required.

However, up to and including WordPress 2.9, if you send mail via SMTP, it does not allow you to e-mail multiple recipients in the “to” field. Most users don’t ever have to deal with this limitation, but if you’re using WordPress in one of several ways (such as with a collaboration workflow), this can cause frustration.

Luckily, the wp_mail() function can be overridden. Specifically, you want to replace this code:

The best practice in such a case is to use a plugin so that whenever you upgrade WordPress, you won’t lose changes. Here is an example of such a plugin, which copies the default wp_mail() function and makes the change as detailed above. To install it, just rename the extension to “php”, put it in your WordPress plugins folder, and activate it.

Thanks, that worked great! It is hard to believe that we would have to wait for WP 3.0 to get this fixed.

Question: is there a way to modify the code and send mail one recipient at a time, one recipient per TO: ?

Reply from Peter: Yes, you could modify the wp_mail code further, but a cleaner and more maintainable way is for you to change the code that calls the wp_mail function — on a general basis, this means looping through the addresses you have and calling the function once per address. (For my use, I wanted all “to” addresses to be displayed so that everybody knew who else was being e-mailed.)

HI,
Is there a way to included the post content in the email? We want people to be able to review the post via their mobile email.

Reply from Peter: I’m assuming that you’re referring to the collaboration e-mails plugin? You could certainly edit the pce_pending() function in the plugin file and output different aspects of the post as available in the $pce_object variable.

Contact Me

Comment on any of my posts to contact me. Your e-mail address will only be visible to me and not to the public. If you want to contact me in a more private manner, e-mail peterkeung.biz. Hire my web consulting services at Mugo Web.