The email could not be sent. possible reason: your host may have disabled

I was unaware of this very common issue until I migrated my blog from the blogger platform to wordpress and hosted it on vultr and then moved it to digitalocean’s lightning fast cloud hosting. one day i forgot my wordpress admin account password and tried to reset it. and to my surprise I got the following error message saying “your host may have disabled the mail() function”.

Could not send email.Possible reason: Your host may have disabled the mail() function.

I searched the internet that day and discovered that it is a very common problem that people keep finding a solution for in various situations. Some would look for a solution when they are unable to receive any email from the contact form on a wordpress site, while others had issues with the comment moderation email not being sent to the website admin. while others had the biggest problem accessing their wordpress dashboard as the password reset email is never sent to the registered email account and they get the error saying “your host may have disabled the mail function ( )”. so how to fix this problem of wordpress not sending any email?

whatever your concern is, it always cripples you especially when you are running your website on a linux based vps(virtual private server) without any graphical interface like cpanel or plesk. Most of the fast vps servers are configured on ubuntu or centos. managing them on your own is really hard work, especially when you are not an expert in linux based commands. vultr, digitalocean, cloudcone, linode, and atlantic.net are some of the top names on the list of the world’s fastest and best cloud hosting service providers. everyone can sign up for a web hosting account using the lamp (linux, apache, mysql and php) or lemp (linux, nginx, mysql and php) software stacks. and you may have a similar problem with wordpress hosting on any of them.

It is a very common issue that the php mail() function, which is responsible for sending wordpress related emails such as password reset emails, comment notifications, contact form emails, is not enabled or set by default. In this post, we will discuss about what is php mail() used for in wordpress and how to enable it to allow wordpress to send password reset emails. I will also show you a very easy way to enable and configure the php mail() or mail() function on the vultr cloud computing server (vultr virtual cloud hosting server).

php mail() function in wordpress

wordpress is based on php and uses php mail() to send emails in different situations. it is also known as “wp_mail()” function or simply “mail()” function. however, the php mail() function uses a program called “sendmail” to work or send email using “sendmail_path”. often this program is installed by default with your lamp or lemp stack. “sendmail” settings and configurations are also updated in the “php.ini” file that is used by the web server to execute hundreds of tasks.

so basically any website built in php can take advantage of the php mail() function to send email directly from your website without asking you to provide the smtp or login password for the email account used for to send e-mails. this is actually not as good as it sounds because anyone can configure their website to send mail for any xyz domain, which is always the reason why most wordpress emails are marked as [spam] by gmail, yahoo , outlook or other similar emails. – mail providers. sometimes they are even blocked by gmail, yahoo or other email providers to prevent spam and secure your network. that is also the reason why some wordpress hosting providers ask their users to only use the email associated with the domain wordpress is installed on. Some providers also use security policy to block wordpress emails from being sent from a domain other than the one wordpress is installed on. but here we will focus on the php mail() function, which cannot send wordpress emails. let me mention the most common reasons why “wordpress won’t send emails on cloud hosting services like vultr, digitalocean, cloudcone, etc”.

  1. php mail() function is disabled in php.ini
  2. misconfiguration of hostname in /etc/ hosts or virtual host (vhosts) files
  3. sendmail‘ not installed
  4. sendmail misconfigured or missing ‘sendmail_path‘ in php.ini file
  5. firewall is blocking traffic
  6. smtp port is blocked by the hosting provider
See Also:  The 5 best email hosting services for business in 2022 | Zapier

#1. php mail() function is disabled in php.ini

your host may have disabled the mail() function

To find out if the php mail() function is disabled in the php.ini file, you must first open the php.ini file. the ‘php.ini‘ file is often found in a folder under /etc/php/. your path varies depending on the version of php and os installed on your vps. in wordpress one click app with vultr the path to php.ini file is “/etc/php/7.0/fpm/php.ini” while same wordpress one click app in digitalocean (with lamp) it has its path in “/etc/php/7.2/apache2/php.ini“. you can easily find the php.ini file path by uploading a simple php file with the following script on your hosting server.

<?phpphpinfo();?>

simply copy the php script written above and paste it into a text editor like notepad++ or notepad or textedit on mac and save it as info.php. upload the info.php file to the root directory of your wordpress website, which can be /var/www/hawkdive.com/html/ if not changed.

after loading the info.php file, try to access it by typing the following url:http://ipaddress_of_your_server/info.php or http://yourdomainname.com/ information .php

this url will open a web page with tons of information about the php version, its settings and configuration. look for the “loaded configuration file” option and note the path of the php.ini file.

Path Of Php.ini File- your host may have disabled the mail() function

Path of php.ini file

Now SSH to your Cloud hosting server or VPS using puTTY or Console. Type the following command to read and edit php.ini file.

sudo nano /etc/php/7.0/fpm/php.ini

now look for the “disable_function=” directive, if you have mail there, just delete the mail and press “ctrl+x” to exit and type “y ” to commit the changes if there are any and press enter to confirm writing the file. now try resetting the password and see if you still get the same error saying “your host may have disabled the mail() function”.

#2. misconfiguration of hostname in /etc/hosts or virtual host (vhosts) files

There are two host files you want to check here. if any of them have wrong settings, your wordpress will not be able to send any email. open the console or login to your vps by ssh and type the following command.

You should see something similar to one of the following

or,

If you see something similar to any of the above, you’re fine. if not, just copy the second line “127.0.0.1 localhost localhost.localdomain yourhostname” replace “yourhostname” with the actual name you want to give your server, like “webhost” or “darvis” or something”. press ctrl+x to exit, say yes to save changes and press enter. if you are in vultr and your “/etc/hosts” is blank or never created, create the file and pass only the second line.

editing the virtual hosts (vhosts) file

once the /etc/hosts file is created or updated, you need to check the virtual hosts file. virtual host files are used to host multiple sites on the same vps server. has a different path depending on the operating system. nginx on lemp stack has its virtual hosts file located at /etc/nginx/conf.d/ while apache on lamp stacks has its path at /etc/apache2/sites-available/ . vultr installs lemp with the one-click wordpress app, and the default vhosts files are “/etc/nginx/conf.d/wordpress_http.conf” and “/etc/ nginx/ conf.d/wordpress_https.conf.” Open both virtual hosts, also known as server blocks or nginx configuration files, and update the “server_name” attribute to your domain. wordpress website, you may see a “_” as a value for “server_name”, you just need to replace it with the actual domain name and it should look something like this.

Nginx Server Block Configuration File

Nginx Server Block Configuration File- Vultr Setup

Do the same with “/etc/nginx/conf.d/wordpress_https.conf” and save the file by pressing CTRL+X, then say yes and hit enter to save. After both the file are updated restart the Nginx service by typing:

See Also:  How to fix gmail not opening links on android

on the apache server

if you are on an apache server or using lamp stack like digitalocean’s one click wordpress app, type the following commands to open virtual hosts files and make sure that servername and serveralias attribute has the correct address, as shown below.

sudo nano /etc/apache2/sites-available/000-default.confsudo nano /etc/apache2/sites-available/default-ssl.conf

an example apache virtual host file in my digitalocean droplet.

after you have fixed or updated the virtual hosts, simply press ‘ctrl+x’ and press ‘y’ and press enter to save your changes.

#3. ‘sendmail’ is not installed

One of the main reasons why php mail() doesn’t work with the wordpress application is that you don’t have the sendmail application installed. to check whether sendmail is installed or not. just type the following command.

sendmail myemail@gmail.com

if sendmail is installed, it will give you a blank line with a blinking cursor to write your message; otherwise you will see the following error.

if you see the error, type the following command to install sendmail:

note: some hosts, such as digitalocean, may not have sendmail installed, while others may have an outdated version of the sendmail application and still show no errors except a blank line . in such cases, just go ahead and try to install the sendmail application.

sudo apt-get install sendmail

after installing sendmail, restart apache by typing ”

sudo systemctl restart apache2

if it’s nginx (as in vultr cloud computing), type:

systemctl restart nginx.service

now check your wordpress contact form by sending any message or try to reset your wordpress user account password. you should now receive emails. If wordpress still can’t send emails or you still see the same message: “email can’t be sent, your host may have disabled the mail() function”, then continue with the next steps.

#4. sendmail misconfigured or missing ‘sendmail_path’ in php.ini file

There may be a possibility that sendmail is not running or is misconfigured. you can run the “sendmailconfig” command to rebuild the sendmail configuration. type the command:

you just need to answer ‘y’ to all questions during setup and finally restart apache.

sudo systemctl restart apache2

check if the ‘sendmail_path‘ is correct in the php.ini file. you can also confirm this from the info.php script as mentioned in step #1. just access the url of the script and search for “sendmail_path”, it should have the value “/usr/sbin/sendmail -t -i” as shown in the image below.

Sendmai_Path in PHP info script

Sendmail_Path in PHP info script

If the “sendmail_path” attribute has a value other than what is mentioned above, then open php.ini file and Find the following line:

and set its value to “/usr/sbin/sendmail -t -i” (no double backtick). also make sure the other attributes for [mail function] in php.ini are similar to what I have on my vps as mentioned below.

after you have corrected the values, finally restart your apache or nginx web server.

sudo systemctl restart apache2systemctl restart nginx.service

note:- You can also restart the mailing service to update the updated values. just type the following command: sudo /etc/init.d/sendmail restart

#5. the firewall is blocking the traffic

ubuntu 16.04 or 18.04 servers have a basic firewall called ufw (uncomplicated firewall) that only allows connections to certain services. it is the best and easiest firewall configuration tool for iptables which is included and installed with ubuntu by default. so if your wordpress website also gives an error saying: ‘your host may have disabled the mail() function’, it is more likely that the ufw firewall is enabled and blocking the outgoing smtp port and it is because that your wordpress site can’t send emails. To check the status of the ufw firewall or to see if it is running, stopped, or blocking any ports, run the following command.

sudo ufw status

Mail servers, such as sendmail and postfix, use port 25 or 587 by default to send email. however, you can cause them to change the way mail is delivered by configuring a rule to listen for mail delivery on a different port.

See Also:  Gmail cho ios

Based on the above command and its output, we clearly see that the ufw firewall is enabled and is blocking or denying the smtp port for outgoing traffic (in red) while internal smtp (in blue) is allowed. now if that is the case with your server you can simply remove those smtp rules and enable wordpress email or php mail (function) right away. use the following command to remove the smtp filter rules.

now reload the ufw firewall by typing the following command.

Also restart your server for the changes to take effect. type the command:

/sbin/turn off -r now

You can also run “iptables -l” to show all firewall rules and “iptables -f” to remove all rules from the chain.

If the problem is still not solved, try after disabling the firewall temporarily. type the command:

now if you check the firewall status it should say down. restart your server and check if mails() is working now.

#6. the smtp port is blocked by the hosting provider

this is another common reason why wordpress can’t send emails or php mail() function wp_mail() doesn’t work. Most hosting providers especially vps or cloud hosting providers block SMTP port for outgoing connection or apply filter based on user account to combat spam and spam-like activities. in such cases there is nothing you can do except contact your service provider and ask them nicely to open port #25 for you. vultr often disables the smtp port on new users and opens it after requesting and provide them with the information they may request.

but before contacting them you need to be 100% sure if the smtp port is blocked on your account. type the following command to see all available processes and the port they are listening on.

Check All Processes and Port they are Listening upon

Check All Processes and Port they are Listening upon

As in the above picture, we see that sendmail process is available and the port 25, 443 and 587 is open for it to listen. If you do not see sendmail or any mail program in the list, then you won’t be able to send mail out until you choose and setup a different port or remote service.

now if you already tried all the steps mentioned above from #1 to #5 and you still can’t send email or wordpress email still doesn’t work through. try the following command to check if you can connect to an external host on smtp port 25.

if it connects, that means the smtp ports are open and working fine and the mails are not delivered for some other reason which affects the recipient’s server. there may be a chance that the recipient’s mail server is treating this email as spam and discarding it before delivery.

on the other hand, if you never connect to any external smtp host, you should contact your hosting service provider because it could be an smtp filter applied from your end. and the error message saying “your host may have disabled the mail() function” could be true

if the service provider is not blocking the port and you have verified and followed all the steps mentioned above, but wordpress is still not sending emails to your wordpress admin email id. try replacing the admin recipient email with an email from another service provider. If the problem persists, try the following command to trace the email path.

now try sending a message from a contact form on the wordpress site or reset your wordpress account password to see if it works fine. I hope that one of the steps mentioned above has fixed the problems related to php mail() and you no longer see the error: “your host may have disabled the mail() function”. however, if you can’t fix this problem yourself or have other issues on your way to solve the exact problem, just contact me via skype:live:hawkdvetech or email me. please share this article, if you liked it.

Leave a Reply

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