Email


System Emails

Email in WordPress is powered by the open source PHPMailer library. The problem is that it’s a bit unreliable for deliverability and often the target of spammers. In my post on security, I recommend outsourcing mail from your server. Instead of using PHP mail() with sendmail or postfix, I prefer to reroute all email through SMTP ( Simple Mail Transfer Protocol ) by adding settings in the theme that allow the site owners to configure a number of third party email services. I’ve found that the best choice for a third party provider is the one they are already using, which is usually Microsoft, Google, Yahoo or whatever. The only time I recommend otherwise is if the site has a high volume of transaction emails like a membership or an e-commerce website in which case I generally recommend Mailgun or Amazon SES. I’m particularly fond of setting up Google Apps Suite Workplace because of it’s flexibility to cover some other online needs that usually accompany a decent online presence like email, calendars, messaging, video chat, contacts etc.

STMP Options

One of the best features of using SMTP for mail is the ability to keep a log of all sent emails right in the account which doesn’t put any additional load on WordPress or log bloat into the database. I’ve also found that it’s a convenient way to check on a site activity by just checking the sent emails. In order to reroute the default system phpmailer through SMTP, I prefer to set the variables in either the config file or the .env settings. I require one file for the theme that is under 100 lines to do so. It hooks into the phpmailer_init action on load.

I don’t want to lock into any site into reliance on SMTP so I’ve added a setting in the site options to Enable SMTP and to test the system email.

Configuration options for wp-config.php:
<?php /* wp-config.php */
//define('GLOBAL_SMTP_DISABLE',true);
//define('GLOBAL_SMTP_DEBUG',true);
define('GLOBAL_SMTP_HOST','smtp.whatever.com');
define('GLOBAL_SMTP_PORT',465);
define('GLOBAL_SMTP_USER','USER@DOMAIN.COM');
define('GLOBAL_SMTP_PASSWORD','PASSWORD');
//define('GLOBAL_SMTP_FROM_NAME','');
//define('GLOBAL_SMTP_FROM','');
//define('GLOBAL_SMTP_SECURE;','ssl');
//define('GLOBAL_SMTP_RETURN_PATH','');
//define('GLOBAL_SMTP_REPLYTO_FROM','');
//define('GLOBAL_SMTP_REPLYTO_FROM_NAME','');

** Note: Do NOT use your default email address and password. Almost all providers now offer ‘application specific passwords’. Another thing I like to do is to alias a secondary email address for the website to use so that those emails are easily distinguishable in your inbox.

Notifications

I also like to set up custom email notifications for site editors because I think they’re helpful. I also setup admin notifications for any site I manage so that I’m notified of any site errors. I set custom update notifications for the DWP Theme and Plugin upgrades on all sites. I set other custom notifications based on the per site usage. If a site registers users, I’ll set new user registration notifications. If a site has custom forms, I set notifications for those.

HTML Emails

I like to set up custom HTML email templates if a site has e-commerce, custom form responses, or involves user registration. It just adds an extra bit of professionalism to the site communications. I’ve gone back and forth between including a custom HTML email template and allowing users to design their own with a plugin. I prefer the later because I end up spending too much time tweaking the email templates. There are three plugins I prefer to work with for HTML emails in WordPress. A combination of these three can tackle every aspect of email design, newsletters, and system notifications reliably.

Because e-commerce sites generate a lot of automated emails outside of the typical system notifications and I always use WooCommerce for WordPress sites, I prefer to use use the WooCommerce email customizers.