fix-wp-not-sending-email-issue
Home » BLOG » WordPress » How to fix WordPress not sending Emails issue

How to fix WordPress not sending Emails issue

category:  WordPress

Issues with email sending are some of the most common questions that I have from my clients. Often, the clients are not seeing any of the expected WordPress notifications. This is usually due to problems with their server configuration or their contact form setting.

Server configuration

WordPress is built in PHP which is one of the most popular server script languages. WordPress uses the PHP mail function to send out emails. Normally, web hosting that supports PHP and WordPress will be configured to send an email for your WordPress site. When you install WordPress or migrate WordPress to these web hosts, the sending of the email should work without the need for configuration. However, some web hosts disable the PHP mail function because it is easily exploitable by spammers and hackers.

Install the Post SMTP plugin for email testing

In order to identify if this is the case, first, you want to know if the email is actually being sent out from your WordPress or not. We will use the Post SMTP plugin for email testing.

Follow the steps below.

  • Install the Post SMTP plugin on your WordPress site and activate the plugin
  • Navigate to Post SMTP>Post SMTP
  • Then click on Send a Test Email
  • Enter the Recipient Email Address and click Next
  • The Post SMTP plugin will try to send an email out.
  • If the email is sent, you will see the successful message on the screen and you will receive the test email from the Post SMTP plugin in your mailbox.
  • If the email is NOT sent, you will see the failure message on the screen. You will see the status message telling you what is the problem.
  • Additionally, the Post SMTP plugin offers an Email Log feature for free. So you can check the sending email status from there.

If your sending email test fails, the cause likely comes either from server configuration or your web host disabling the PHP mail function. You should contact your web host for further details.

Contact form setting

The Contact Form is one of the MUSTS on a website. The visitors can easily contact you via the form rather than having to copy and paste your contact email to their mail application. This is an essential convenience when the visitors contact you via their phone.

If you never got the WordPress notification in your mailbox (a copy of an entry from the contact form), but the contact form shows a successful message, the problem may be the form setting. You see the successful message on the screen which means your server can send out the mail (the PHP mail function receives the success status from the server).

In order to identify the cause, we will use the Post SMTP plugin that I mention above. Make sure the plugin is activated.

  • Now, enter the message on the contact form on your WordPress site and hit the send button for submitting the contact form.
  • Next, navigate to Post SMTP>Email Log at the WordPress backend.
  • Check the status of your message from the email log page
  • If the status is “Sent“, that means the WordPress site is able to send the email out but the received mail server didn’t deliver the email into the mailbox.

In my case, I use the WPforms plugin. I got the “Sender prohibited by SPF” error. The reason that I got the “Sender prohibited by SPF” error is because my form setting is incorrect.

Cause

Here is my form setting in the WPform plugin

  • Send to Email Address: example@gmail.com
  • From Email: example@gmail.com

As you see I use the same email address for both settings. Some email providers will flag the message as spam or block it from being delivered because the spam filters try to detect that an email is really coming from the location that it claims to be from.

Solution

To solve the issue, I changed the email address from the From Email setting from example@gmail.com to wordpress@mydomain.com. Using a domain-specific email address at the From Email solves the issue.

For example, if your domain name is abc.com, you will enter wordpress@abc.com at the Form Email. The wordpress@abc.com doesn’t need to be created since we never use this email to receive any emails. This solution can apply to other contact form plugins such as Contact Form 7.

What if, you want to use your specific email at “From Email”

For the solution above, at the received email header, it will show the wordpress@yourdomain.com in the From field because you set the From Email as wordpress@yourdomain.com in the Wpform setting. If you want to use other emails instead of wordpress@yourdomain.com, you can send the email via SMTP instead of using the PHP mail function which is a default mail function that WordPress uses.

What is SMTP?

SMTP stands for Simple Mail Transfer Protocol. It is an internet standard communication protocol for email transmission. SMTP uses proper authentication for your domain. Because of the authentication, spam filters will give the green light for your email and this email will go to the inbox. PHP mail function doesn’t have SMTP authentication.

Popular SMTP sending email service

You can sign up for those SMTP services and add the SMTP configure into the contact form plugin. So that the contact form will use SMTP authentication for sending the email for your form.

The SMTP authentication will help your email avoid flagging as spam or blocked for receiving.

What if, you want to configure SMTP into the WordPress site without plugin

If you are a developer and create your own contact form, you can use PHPmailer and your SMTP configuration. You can add the code into the functions.php or your own custom plugin.

Note that, WordPress comes with PHPMailer class. It is available at website.com/public_html/wp-includes/class-phpmailer.php

Side note, if you use the contact form plugin, you don’t need to continue with the code below. Because the contact form plugin allows you to configure the SMTP via its plugin.

Here is a code example.

  • Create the constant variables in wp-config.php. In the future, you can change the SMTP configuration from this wp-config.php
define( 'SMTP_HOST', 'mail.yourmailserver.com' );  
define( 'SMTP_AUTH', true );
define( 'SMTP_PORT', '465' );
define( 'SMTP_SECURE', 'ssl' );
define( 'SMTP_USERNAME', 'username@example.com' );  
define( 'SMTP_PASSWORD', 'password' );          
define( 'SMTP_FROM',     'applerinquest@example.com' );  
define( 'SMTP_FROMNAME', 'Apple Rinquest' );   
  • In functions.php or your own custom plugin, add this code below.
add_action( 'phpmailer_init', 'ar_smtp_email' );
function ar_smtp_email( $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = SMTP_HOST;
    $phpmailer->SMTPAuth   = SMTP_AUTH;
    $phpmailer->Port       = SMTP_PORT;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->Username   = SMTP_USERNAME;
    $phpmailer->Password   = SMTP_PASSWORD;
    $phpmailer->From       = SMTP_FROM;
    $phpmailer->FromName   = SMTP_FROMNAME;
}

Now, your WordPress site is configured to use your SMTP.

  • So you can call wp_mail() for sending the email by using your SMTP authentication.
wp_mail("receiver@example.com", "Test Subject", "Test Message");

Wrap up

WordPress won’t send emails out, which is one of the commonly known issues. To perform the troubleshoot, first, check whether the server configuration is correct or not by installing and activating the Post-SMTP plugin. The Post SMTP plugin will log the sent email. If none of the emails are sent out, the fail status will show on the email log. Then you need to check the server configuration. If the emails are sent out, the successful status will show on the email log. Meaning your server configuration is correct. But you don’t get the email from the form even though you see the successful message from the form, meaning your form setting is wrong.

For the form setting, you should check the “From Email” field or add the SMTP authentication. Mostly these two methods will work.

And that’s it. I hope my post is helpful and save your time. Please consider buying me a coffee. It will make my day.