Viewed   60 times

How can I check a problem with mail being sent on my server? I run a simple test:

if(mail($to, $subject, $message)) {
echo 'Mail Sent';

which the test outputs the text; but, no mail ever arrives.

How can I go about tracking down the issue?



That is quite a long story. A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :

  • Does the sender address ("From") belong to a domain on your server? If not, make it so.
  • Is your server on a blacklist (e.g. check IP on This is a remote possibility with shared hosting.
  • Are mails filtered by a spam filter? Open an account with a freemailer that has a spam folder and find out. Also, try sending mail to an address without a spam filter.
  • Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
  • If you have access to log files, check those, of course, as suggested above.
  • Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.

For german speakers, I have written a quite exhaustive "what to do" on this issue some time ago. See here.

Thursday, November 24, 2022

To send an email you need a SMTP server (local or remote). Actually your mail function just passes the mail to your SMTP server and is this one which really send your email.

In your php.ini appears this line

sendmail_path = /usr/sbin/sendmail -t -i

You should be aware if you use that configuration parameter (from manual):

If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.

But the most important thing here is you just uninstall sendmail so you can expect your mail goes nowhere. I know sendmail was giving you some problems, possibly configuration problems, but now your php.ini configuration is wrong.

How to solve it?

  • Start removing the sendmail_path parameter from the php.ini.

  • Install a simple to configure SMTP server like postfix.

  • Verify postfix is listening at port 22:

netstat -lnt

  • Try to send a mail from your php mail() function

  • Verify your mail has been sent correctly (check your /var/log/mail.log or /var/log/mail/mail.log files)

  • You also can verify the mail is not in the postfix queue:

postqueue -f

Thursday, December 22, 2022

I Finally got a laaaaarge smile on my face. Working together with @DaveRandom, He helped me come up with these codes:

NOTE: The code bellow uses PHPMailer


            $senderName = 'Erick Best'; //Enter the sender name
            $username = ''; //Enter your Email
            $password = 'passwordHere';// Enter the Password

            $recipients = array(
                '' => 'Erick Best',
                '' => 'Yahoo User',
          ///That's all you need to do

//No need to edit bellow    
            require '../PHPMailerAutoload.php';

            //Create a new PHPMailer instance
            $mail = new PHPMailer();

            // Set up SMTP
            $mail->SMTPAuth   = true;
            $mail->SMTPSecure = "tls";
            $mail->Host       = "";
            $mail->Port       = 587; // we changed this from 486
            $mail->Username   = $username;
            $mail->Password   = $password;

            // Build the message
            $mail->Subject = 'PHPMailer mail() test';
            $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
            $mail->AltBody = 'This is a plain-text message body';

            // Set the from/to
            $mail->setFrom($username, $senderName);
            foreach ($recipients as $address => $name) {
                $mail->addAddress($address, $name);

            //send the message, check for errors
            if (!$mail->send()) {
                echo "Mailer Error: " . $mail->ErrorInfo;
            } else {
                echo "Message sent!";


And this WORKED like VOODOO!... It sent mails to any provider. Including **YAHOO**

Hope it helps someone!

Saturday, August 13, 2022

Have you tried the mailq command to see if there are errors? Here's an answer to a similar question on ServerFault with more detail.

Friday, December 16, 2022

You can get around the MX lookup by adding a short entry into your sendmail /etc/mail/mailertable file.

The contents of the file should probably have a single line like:       esmtp:[]

Save the file and restart sendmail (or rebuild your if it must be done manually).

Friday, November 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :