Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

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 *

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF