Troubleshooting common issues with PHP Mail


  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: FTP Access, Email access
  • Applies to: DV
    • Difficulty: Easy
    • Time Needed: 20
    • Tools Required: FTP Access, Email access
  • Applies to: WordPress Hosting
    • Difficulty: Easy
    • Time Needed: 0
    • Tools Required: None
 

Overview

The following article provides troubleshooting steps and tips that can be taken when you are experiencing issues sending with PHP mail.

Read Me First
Please keep in mind that troubleshooting the configuration/functionality of third-party applications is not covered by our statement of support. These resources were provided as a courtesy to assist you to the extent of our abilities. For more information on our statement of support, please see the following: http://mediatemple.net/legal/statement-of-support/

 

Lets get started!

Check the spam folder

If php mail is not reaching a recipient's inbox, investigation can begin by checking the spam folder.

If php mail is going to spam, it may be necessary to update the spam filter of the receiver, such as whitelisting the sender address.

Third-party search engines such as https://mxtoolbox.com/blacklists.aspx can be used to check if the domain is listed on Real Time Blacklists (RBL). Spam testers such as https://www.mail-tester.com/ can be used to check the probability of an email getting marked as spam.

Check for bounceback messages

Bounceback messages will often contain important information as to why email is undelivered. If you or your contact are receiving bouncebacks, we recommend reviewing the additional documentation below:

Send a php test to different test accounts

Sending to different mail hosts can help determine if the issue is domain specific.

For example, if @gmail.com users are not receiving php mail, then additional tests can be sent to @yahoo.com, @hotmail.com, and/or @aol.com.

Create a simple php mail tester

It can be helpful for testing to use a generic php mail script, as this can help eliminate the effects of third-party variants. To assist you, we have provided a sample php mail script which can be added to your site's root directory via File Manager, FTP, or SSH. After adding this file, it can be accessed through a web browser to send a php test to a desired address.

Filename: email.php

<?php
if (isset($_REQUEST['to']))
{
$to = $_REQUEST['to'];
$to = htmlspecialchars($to);
$host=$_SERVER['SERVER_NAME'];
$ip=$_SERVER['SERVER_ADDR'];
$from="test@$host";
$subject="PHP Mail Test";
$message="This is a test message sent from $host. It originated from the IP address $ip. If you received this email, that means that the PHP mail function is working on this server.";
$headers="From: $from" . "\r\n" . "Reply-To: test@$host" . "\r\n" . "X-Mailer: PHP/" . phpversion();
$success=mail($to,$subject,$message,$headers);

$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
if (preg_match($regex, $to)) {

if($success) {
echo "The email was sent successfully";
}
else {
echo "An error occurred, and the email was not sent. Check your domains' error logs and mail log for more info.";
}

} else {

echo "
<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit'>
</form><font color='red'>";

echo $to . " is an invalid email. Please try again.</font></center>";

}}

else
{
echo "<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit' value='Send Message'>
</form></center>";
}

?>

If php mail is received while using a generic script, then it can be determined that the server's php mail is functional.

If you are still unable to receive php mail using a third-party application, that would indicate the issue's origin to be at the development level. In this case, it would be advised to contact your website's developer for further troubleshooting.

Checking PHP Mail Logs

If all the troubleshooting methods are attempted and php mail is still not being received, please feel free to contact our Support Staff by submitting a support request, opening a support chat, or by calling us at 1.310.841.5500.

Due to the shared-nature of the Grid, php mail logs are reviewed by Media Temple Support.

Let's Get Started

Check the spam folder

If php mail is not reaching a recipient's inbox, investigation can begin by checking the spam folder.

If php mail is going to spam, it may be necessary to update the spam filter of the receiver, such as whitelisting the sender address.

Third-party search engines such as https://mxtoolbox.com/blacklists.aspx can be used to check if the domain is listed on Real Time Blacklists (RBL). Spam testers such as https://www.mail-tester.com/ can be used to check the probability of an email getting marked as spam.

Check for bounceback messages

Bounceback messages will often contain important information as to why email is undelivered. If you or your contact are receiving bouncebacks, we recommend reviewing the additional documentation below:

Send a php test to different test accounts

Sending to different mail hosts can help determine if the issue is domain specific.

For example, if @gmail.com users are not receiving php mail, then additional tests can be sent to @yahoo.com, @hotmail.com, and/or @aol.com.

Create a simple php mail tester

It can be helpful for testing to use a generic php mail script, as this can help eliminate the effects of third-party variants. To assist you, we have provided a sample php mail script which can be added to your site's root directory via File Manager, FTP, or SSH. After adding this file, it can be accessed through a web browser to send a php test to a desired address.

Filename: email.php

<?php
if (isset($_REQUEST['to']))
{
$to = $_REQUEST['to'];
$to = htmlspecialchars($to);
$host=$_SERVER['SERVER_NAME'];
$ip=$_SERVER['SERVER_ADDR'];
$from="test@$host";
$subject="PHP Mail Test";
$message="This is a test message sent from $host. It originated from the IP address $ip. If you received this email, that means that the PHP mail function is working on this server.";
$headers="From: $from" . "\r\n" . "Reply-To: test@$host" . "\r\n" . "X-Mailer: PHP/" . phpversion();
$success=mail($to,$subject,$message,$headers);

$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
if (preg_match($regex, $to)) {

if($success) {
echo "The email was sent successfully";
}
else {
echo "An error occurred, and the email was not sent. Check your domains' error logs and mail log for more info.";
}

} else {

echo "
<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit'>
</form><font color='red'>";

echo $to . " is an invalid email. Please try again.</font></center>";

}}

else
{
echo "<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit' value='Send Message'>
</form></center>";
}

?>

If php mail is received while using a generic script, then it can be determined that the server's php mail is functional.

If you are still unable to receive php mail using a third-party application, that would indicate the issue's origin to be at the development level. In this case, it would be advised to contact your website's developer for further troubleshooting.

Checking PHP Mail Logs

Checking mail logs can provide insight as to what exactly is occurring when php mail is attempted by your server. The log locations we would recommend checking is as followed:

Plesk:
/usr/local/psa/var/log/maillog

cPanel:
/var/log/exim_mainlog

For the Managed WordPress Hosting, the PHP mail function is unsupported. If your site requires a function similar to PHP mail (such as a Contact form) the recommended options would include using SMTP, or migrating your site to our shared-hosting or VPS servers which do support php mail.

For information and suggestions on migrations feel free to contact our Support Staff by submitting a support request, opening a support chat, or by calling us at 1.310.841.5500.