Blog

How to send emails in WordPress

Šarūnas Ročevas
· 11 min read · Tips and resources · January 25th, 2024
Sending transactional emails through WordPress blogs or websites can be unreliable. Learn what you need to do to ensure WordPress emails consistently get delivered to the inbox.

WordPress blogs and websites have a reputation for their email delivery issues. This is mostly because every WordPress host configures email sending differently and they are generally not optimized for deliverability. You can never be sure if your emails will reach the inbox or if you’re receiving incoming emails sent through your website! Thankfully, you can fix issues with WordPress sending emails by integrating your WordPress site with a trusted email service like MailerSend.

Note: If you’re using WooCommerce for your e-commerce store, learn how to resolve email-sending issues using MailerSend’s email API and official WooCommerce plugin. Our blog article explains how: ​​WooCommerce not sending emails every time? Here’s how to fix it.

How emails are sent in WordPress with the wp_mail() function

When configured out of the box, WordPress doesn’t actually send emails because it has no email server capabilities. WordPress is a content management platform. It wasn't designed to be an email service, so it relies on the web host to send messages—like contact form submissions, invoices and email notifications—on its behalf. 

To troubleshoot sending emails from WordPress, let’s take a look at how emails are sent from WordPress:

How WordPress sends emails

1. WordPress prepares to send your email using the wp_mail() function below, specifying the recipient, subject, message contents, and any attachments.

wp_mail( $to, $subject, $message, $headers, $attachments );

2. The mail function then calls PHP’s built-in mail() function, part of the PHPMailer library, that instructs the mail server at the WordPress host to send the email.

mail(to, subject, message, headers, parameters);

3. The WordPress host will attempt to deliver your email with varying results, sometimes landing in the spam folder or not sending it at all.

Instead of relying on the web host as a mailer, many WordPress users install a third-party SMTP plugin. The plugin tells WordPress to send emails using Simple Mail Transfer Protocol, so the email delivery is handled by an SMTP host like Gmail SMTP instead of your web host.

How to send emails from WordPress with a plugin

To avoid constantly troubleshooting WordPress deliverability issues and to ensure long-term reliability, the best solution is to use a plugin. You can ensure that your WordPress emails get delivered every time by using a reliable SMTP service like MailerSend.

SMTP services are built for high-volume sending and have established sender reputations with Internet Service Providers (ISPs). This means that ISPs are much more likely to trust incoming mail from their servers and deliver them to the inbox instead of rejecting them or sending them to the spam folder. 

There are plenty of SMTP services and plugins to choose from—of course, we recommend MailerSend’s official SMTP plugin. MailerSend is built by deliverability experts and has an advanced sending infrastructure paired with a spotless sending reputation. Here’s how to get started.

1. Use MailerSend’s SMTP plugin

The MailerSend plugin for WordPress allows you to send emails using a reliable SMTP server. The official plugin saves you time as you only need to enter your SMTP username and password to get started, leaving you to focus on important fields like your sender details and email recipients.

First, sign up with MailerSend if you don’t already have an account. Add a sending domain and then generate a new SMTP user on the domain’s page in the SMTP section. You can now retrieve your SMTP credentials.

For optimal email deliverability and security, best practices are automatically applied such as using SMTP port 587 and TLS for the connection. Click on each field to copy it.

An exmple of the SMTP user credentials in MailerSend.

Install the plugin by searching for MailerSend – Official SMTP Integration. Activate it and then go to MailerSend SMTP in the sidebar. Enter your SMTP credentials from MailerSend under SMTP username and password and then click Save.

SMTP username and password

Under Sender details, enter your name and email address along with any other recipients in the CC, BCC and Reply-to fields. Click Save when done.

SMTP sender details
For best deliverability results, the Sender address domain must match the sending domain where you obtained the SMTP credentials.

Check to see that MailerSend is sending emails from WordPress by clicking the Test button.

SMTP test email

From now on your WordPress emails will be sent through MailerSend’s SMTP server instead of through your web host. As a bonus, you can also track all email activity on the Activity page in your MailerSend account.

For more information about how to enable SMTP in MailerSend, visit the How to send emails via SMTP with MailerSend article.

2. Use another SMTP plugin

Install the SMTP plugin of your choice from the WordPress dashboard. We’ll use Easy WP SMTP as an example here. Once installed, go to Easy WP SMTP under Settings. At the SMTP Settings tab, paste your SMTP credentials from MailerSend. If you haven't done so already, you can follow the steps above to create a free account and retrieve your SMTP credentials.

Easy WP SMTP settings
Depending on your SMTP plugin, choose STARTTLS if you see the option because it will automatically upgrade a plain text connection to an encrypted one. Otherwise, you can choose SSL/TLS.

To check that WordPress is sending emails, you can test your SMTP settings by going to the Test Email tab. Enter a recipient email address and then click Send Test Email to check that emails are being sent using MailerSend’s SMTP server.

Easy WP SMTP test email

How to send emails from WordPress without a plugin

If you feel comfortable editing WordPress themes and want to avoid adding plugins to your website, you can manually configure SMTP in the wp-config.php file. You’ll still need an SMTP service, and you can follow the steps above to create a MailerSend account and retrieve your SMTP credentials. 

Remember: This method is not recommended unless you have experience with editing WordPress templates. You should also use the child theme of your template to avoid losing any changes, and make a backup of your website before you start editing.

1. Connect to your website with an FTP client, like FileZilla. Locate the wp-config.php file. You’ll find this in the root of your WordPress file directory. Download the file and open it to edit.

2. Add the following settings into the wp-config.php file, entering the appropriate values where necessary:

// SMTP email settings
define( 'SMTP_username', 'Enter your MailerSend SMTP username here' );  // host username
define( 'SMTP_password', 'Enter your MailerSend SMTP password here' );   // MailerSend SMTP password
define( 'SMTP_server', 'smtp.mailersend.net' );     // SMTP server address
define( 'SMTP_FROM', 'Enter your from email here' );   // Your Email Address
define( 'SMTP_NAME', 'Enter your business name here' );   //  Business From Name
define( 'SMTP_PORT', '587' );     // Server Port Number
define( 'SMTP_SECURE', 'tls' );   // Encryption - ssl or tls (recommended)
define( 'SMTP_AUTH', true );  // Use SMTP authentication (true|false)
define( 'SMTP_DEBUG',   0 );  // for debugging purposes only

3. Save the changes and sync the file by uploading it back to the server. 

4. In your WordPress dashboard, navigate to Appearance > Theme file editor

5. Open the functions.php file and paste the below.

add_action( 'phpmailer_init', 'my_phpmailer_smtp' );
function my_phpmailer_smtp( $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host = SMTP_server;
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
    $phpmailer->Username = SMTP_username;
    $phpmailer->Password = SMTP_password;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->From = SMTP_FROM;
    $phpmailer->FromName = SMTP_NAME;
}

6. Save the file and you’re all done. 

Send an email with the WordPress API and wp_mail() function

Once you’ve made the changes to the wp_config.php and functions.php files, you can call the wp_mail() function to send an email:

wp_mail("name@example.com", "Subject", "Message");

WordPress will send an email with the SMTP credentials you entered into the wp-config.php file.

How to test WordPress email sending

There are a few different ways to test whether or not your WordPress emails are working properly. Testing is made easier if you’re using an SMTP service and plugin and they provide logging and activity features that can help you track emails.

Test your emails with MailerSend

If you’re using the MailerSend official SMTP plugin, there is a feature to send a test email. Navigate to the plugin and in the Send a test email section, enter the email address you would like to send the test email. You can then check the inbox of the email address, or head to the Activity page in the MailerSend app. 

If you have correctly configured SMTP in WordPress and the email has been successfully delivered, you will immediately be able to see the email here.

The Activity page in MailerSend showing the status of the test email.

Check outgoing email logs

If you’re using other SMTP plugins, it may include email logging where you can check the status of all outgoing emails. One example that provides this is WP Mail SMTP plugin. 

To enable email logging, go to WP Mail SMTP > Settings > Email Log. Check the option Keep a record of basic details for all emails sent from your site. You’ll then be able to enable various other email logging options.

You can then proceed to send some test emails and check their status in the email log. 

If the SMTP plugin you are using doesn’t include email activity or logging, you can install an email logging plugin, such as WP Mail Logging. Send a test email then go to WP Mail Log under the Tools menu. A successfully sent email will look like the following screenshot without any errors in the Error column.

WP Mail Logging log

Troubleshooting the 4 most common WordPress email issues

There are many reasons why you might be having trouble with WordPress sending emails. Here are some common reasons and how you can fix them.

1. WordPress host is not configured for email sending

Email deliverability with WordPress can be a hit or miss if you’re not using an SMTP plugin. This is because the PHP mail function that WordPress depends on is configured differently for every host. Some WordPress hosts even disable email sending to stop spammers!

For WordPress email errors, you will either need to debug your email configuration settings if you’re self-hosting, or contact the technical support team at your WordPress hosting provider.

Remember: Depending on your WordPress hosting plan, your hosting provider may be reluctant to make changes to their email settings to resolve your sending issues. Any changes may negatively affect other customers sharing the WordPress server as well.

2. WordPress emails are going to spam

If WordPress is sending emails but people are not receiving them, the receiving email server may be blocking your emails or sending them straight to spam. A mismatch between your sending domain and “From” email address, or even the contents of your email message, may be raising deliverability red flags with spam filters.

Check your email sender options

To avoid your emails being marked as spam by inbox providers, your From name should be a legitimate email and it should match your WordPress website’s domain name. For example, if your WordPress site is summerbobsleds.com then your “From” address should be tom@summerbobsleds.com and not summerbobsleds@gmail.com.

If you’re using the built-in wp_mail() function to send emails, you can specify the sending email with the $from_email parameter. For third-party WordPress SMTP plugins, you can check the email sending options by going to the plugin’s settings page. For Easy WP SMTP, navigate to Settings and then Easy WP SMTP to see the following.

Easy WP SMTP settings

Check your email message contents

Your WordPress emails may be blocked by spam filters such as SpamAssassin because of spam-like content. Avoid spammy words like “Your FREE account is ready!” in your email subject line and message body. Also, ensure that your email body is not made up of a single large image or that you’re not using ALL CAPS text.

Spammy subject lines
Use an automated tool like MailerCheck, our partner in email list cleaning and inbox optimization. Send a test email to MailerCheck to generate a report highlighting potential deliverability issues like broken links, invalid HTML code, and much more. Learn more with this article: Improve your deliverability even more with Inbox Insights.

Authenticate your sending domain

Spam filters also check if your sending domain is properly authenticated. A domain with missing authentication records rings alarm bells because the person sending the email may not be who they claim to be, raising suspicion that it may be a spammer or bad actor.

When you add new sending domains to MailerSend, for example, you are required to create SPF and DKIM records and add them to your DNS zones. You will not be able to send emails until you complete this step, reassuring inbox providers and recipients that emails are being sent from your email account.

Domain verification step

3. SMTP servers are returning errors

If you’re sending with a third-party SMTP plugin and you see an exclamation mark in WP Mail Logging like the following screenshot, it means that an SMTP error was returned by the receiving mail server. 

WP Mail Logging error

To investigate further, click the View button and then click Raw to read the error message. Unfortunately, it can be hard to interpret SMTP error codes because these codes are configured differently between mail servers.

WP Mail Logging error details

In this example, “SMTP Error: data not accepted” may mean any one of the following errors:

  • The recipient’s mailbox is full

  • Your sending command contains errors

  • You have exceeded your daily sending quota

  • Your server is sending too many emails at the same time

4. Conflict between WordPress plugins

If the first three troubleshooting options don’t fix the issue with WordPress sending emails, there may be a conflict between WordPress plugins. Contact form and SMTP plugins, for example, can sometimes conflict with other similar plugins in your configuration. To verify this, you will need to deactivate all of your plugins and then reactivate them one by one until you can successfully send emails.

WordPress plugin conflict

Take control of your WordPress emails

WordPress is a powerful and popular publishing platform for blogs and websites, but it lacks a built-in email infrastructure. That’s where an email service provider like MailerSend comes in. As well as more reliable email delivery, you’ll also gain access to features such as analytics, real-time activity, an email API, and a lot more. By combining WordPress and MailerSend, you’ll deliver a positive experience for every website or blog visitor.

How are you sending emails from WordPress? Share in the comments below.

Šarūnas Ročevas
Designer