November 21, 2024

WordPress: How to solve the mail() function error

Each blog created in WordPress has, at least, one feature that needs email to work. In my case, I was testing the “Contact Me“ form when I got the following message:

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

There can be several things triggering this error, so let’s start with a little debugging to understand a little bit more about the issue. The key was trying to understand why the host would have disabled the “mail() function” since it’s something essential to each blog.

 

What is the “mail() function” error?

My first instinct was to check if the PHP mail extension was on. You can check this on your CPanel > Software > Select PHP Version (your CPanel can have different naming for this). It varies from PHP version, but you can quickly check if there’s anything related to email selected.

After that, you can check if your provider allows you to send emails. To do this is quite simple. In your CPanel, you should also have the option for a “Terminal” where you can run commands. Access the terminal and type the following:

echo testing | mail -s EmailSubjectIsSending myemail@gmail.com

If the email arrives, then your system is fully capable of sending emails so that the issue could be elsewhere.

Finally, I wanted to check if there is a plugin that can help me with this. I found the “WP Mail SMTP by WPForms.” It’s free, so I just tested it to see how it performs.

With this, you’ll be able to test if you can use the WordPress SMTP and PHP Mailer and check again if I can send emails. By using this plugin, you’re overriding the settings so that all emails go through the system you configure here. I went straight to the ”Email Test” and tried with the following error:

No luck. It doesn’t return a “mail() function” error, but it doesn’t work anyway. But it opened some new possibilities because, with this plugin, I could define a Mailer or define my SMTP. I’ll explore both options in the following sections.

 

Solution 1: Setting Up a Mailer

It’s the most robust solution since they provide you with a stable email platform where you can send a massive number of emails and ensure that they are received. These systems can remove a lot of the friction and deliver the email “properly” so that the SPAM filters won’t consider you as a bad actor.

To check the options, select “General” and scroll down to “Mailer.”

There are five options, one of those we already tested with no luck. There are three other from companies that have a good track record, and with varying prices, so I’ll let you do your research on which one to use. The plugin provides easy to understand steps on how to configure them so no need to go over them here.

Good

  1. Good practices in delivering email
  2. Some offer free tiers so, for low volume, you can even use them for free

Bad

  1. If you start scaling your business, the prices can go up quite quickly.

 

Solution 2: Setting up your SMTP

Like mentioned before, this is a more unstable solution, since the system is not designed for sending bulk emails, but for your day-to-day email needs. Only use this system if your system sends a relatively low volume of emails. Also, since there’s no control on when the system sends the emails, be aware some email providers may consider your emails as SPAM.

In my case, I want all emails to go with the support email, and this is already configured for me automatically with the proper DKIM and SPF, certificates. These ensure that the email is from a trusted source. This description is an oversimplification, but since your email provider may take care of this for you, you don’t need to worry about it.

Since I would have a low volume of emails, I decided to configure the SMTP with the configurations of my support email. To do this, select “Other SMTP. “

Check your settings to ensure all is correct, then send another test email.

The test email arrived correctly on my inbox:

Good

  1. Easy to setup
  2. Free if you have the account configured

Bad

  1. You should not use this system to send bulk emails.
  2. If not appropriately configured, SPAM filters will consider emails as SPAM.

 

Final Thoughts about “mail() function” error

There are advantages and disadvantages to each approach. You must know what features will send emails and, roughly, how many. It will allow you to make a decision. If you have any e-commerce related needs, use a Mailer to deliver your emails. You can’t afford to have customers complaining that the confirmation email didn’t arrive after they paid the product, for example.

Also, you don’t want to be surprised with a massive bill because you’re sending more emails than expected.

I understand that I didn’t figure out the problem the fundamental issue of why WordPress was returning the “mail() function” error. Still, this solution ended up being better in terms of security and control of how the system sends the emails.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other tutorial-related articles here.

Featured Image by chuttersnap on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

One thought on “WordPress: How to solve the mail() function error

  1. After reading Manuel’s blog post on solving the mail issue in WordPress, it’s great to see an alternative solution to the problem. While the article mentions popular plugins, such as WP Mail SMTP and Gmail SMTP, it’s important to note that there are other options available. One such option is the Postman SMTP plugin, which provides a simple and effective solution for sending emails from your WordPress site. I highly recommend giving it a try, as it may just be the solution you’re looking for. Thanks for sharing this informative post, Manuel!

Leave a Reply

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

Mastodon