Bobcares

wp_mail() function not working? Here’s how to fix it

by | Nov 19, 2018

WordPress website owners prefer the built-in “wp_mail() function, because they can send emails easily.

But, sometimes wp_mail() function doesn’t work properly due to server security restrictions, IP blacklists, etc.

My wp_mail() function not works” is a common problem raised by WordPress owners.

At Bobcares, we resolve such WordPress errors as part of our Outsourced Technical Support for web hosting providers.

Today, let’s have a look at the top 5 reasons for this error and how we fix them.

 

What is “wp_mail() function not working” error?

You try to send emails from your WordPress contact form using wp_mail() function, but it fails to send.

So, it could mean:

  • wp_mail() function can’t generate emails.
  • The wp_mail() function generates emails, but are not delivered to the recipients.

 

What can be the problem? Let’s take a quick look.

 

Reasons and Fixes for “wp_mail() function not working” error

In our experience of handling WordPress issues, the common reasons of this error are mainly:

 

1) Disabled PHP mail() function

PHP mail() is an inherently vulnerable function. Hackers can exploit it and send spam.

To prevent this, some hosts may disable this mail() feature.

In such cases, users receive this error when they send emails from a web-script.

The e-mail could not be sent. Possible reason: your host may have disabled the mail() function.

 

How we fix?

In such servers, we help website owners configure their sites to send mail via the SMTP port instead of the PHP mail() function.

For this, we set up plugins and modules for websites such as “WP Mail SMTP” .

In this way, all mails from the websites bypass PHP mail function, and are sent through the SMTP port of the mail server (like how mail clients like Outlook work).

 

2) wp_mail() not defined in mail script

Users who use custom email scripts will receive this error if they haven’t defined the wp_mail() function or its location in the mail script.

PHP Fatal error: Uncaught Error: Call to undefined function wp_mail()
How we fix?

By default, wp_mail() is defined in “wp-includes/pluggable.php“.

Our Support Engineers, add the following line in the mail script before the function wp_mail() is called.

require_once(“wp-load.php”);

 

This will load all the WordPress core files which specifies the location of wp_mail() function.

3) Compatibility issues with Mail plugin and PHP version

In some cases, compatibility issues with mail plugins and the server PHP version may cause the plugin not to send emails using wp_mail().

In such cases, users will see errors like:

PHP Fatal error: Cannot redeclare wp_mail() (previously declared in …/wp-includes/pluggable.php:173) in …/plugins/mailgun/includes/wp-mail-api.php on line 414″

 

How we fix?

Our Support Engineers, contact the WordPress owners and upgrade the plugin to the latest version.

Prior to the upgrade, we make sure that full backup of the website files and databases are available in case anything goes wrong.

If the above options don’t work,  we’ll continue with the below checks.

4) Emails stuck in mail queue

This is one of the common causes.

wp_mail() function generates mails, but they are stuck in the mail queue. It can be due to various reasons.

  • High load on the server.
  • Spamming in the server.
  • A domain reached its outgoing email limit.

 

How we fix?

To handle load issues, our Server Support Engineers first identify the resource that is being abused. Then, we identify which service is abusing that resource.

At this point, we identify the user who owns the script or software for abusing the service.

To fix spam problems, we identify and disable the email account or mail script that is abusing the mail service.

 

5) Emails rejected by recipient mail server

Sometimes, the recipient mail server can reject emails from your domain.

The major reasons for this rejection are:

  • Absence of a valid SPF record for the sender domain.
  • Recipient server blacklist the sender domain.
  • In case of contact forms, some servers block the emails, when the email address specified in the header is from a completely different server.
  • If the domain is blacklisted in major RBLs , the emails are rejected by some servers.

 

How we fix?

Here are the actions that we take to solve the above mentioned problems.

We check the SPF record of the sender domain with the command:

dig domain.com TXT

If any issues noted with the SPF record, we correct this in the DNS records of the domain.

To resolve the IP blacklist problem, we identify the spam source and submit a delist request to the corresponding RBL.

In case of domain blacklisted at the recipient end, this domain needs to be white-listed by the recipient.

 

Conclusion

wp_mail() function not working” is a common problem raised by WordPress website owners. It can be due to security restrictions, IP blacklists, etc. Today, we’ve seen the top 5 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.