Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

PHPMailer runs without an error, but no email arrives

ErrorNo exception, no output, and no email

Short answer

PHPMailer is quiet by default, so a failed send looks like success. Create it with new PHPMailer(true) and catch the exception, print ErrorInfo, and set SMTPDebug to level 2 to see the server's replies. Also confirm isSMTP() is called, otherwise PHP's mail() is used.

  • Applies to PHPMailer 6, PHP 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the send with debug output on and the error caught. The transcript of the SMTP conversation usually names the problem.

    $mail = new PHPMailer\PHPMailer\PHPMailer(true);
    $mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
    try {
        $mail->send();
    } catch (Exception $e) {
        echo "Mailer Error: {$mail->ErrorInfo}";
    }
  2. 2Match what you see, then jump to its fix

    1. 1Your script prints its own success line even though no mail was sent.Errors are never reported because exceptions and debug are offFix
    2. 2Could not instantiate mail function, or no SMTP lines appear in the debug output at all.isSMTP() was not called, so mail() is usedFix
    3. 3The debug output stops after the connection, or the server closes it.The encryption mode and the port do not matchFix

What does the error look like?

  • No exception, no output, and no email
  • Message could not be sent. Mailer Error:
  • Could not instantiate mail function

Cause 1 of 3

Errors are never reported because exceptions and debug are off

1Check

The README example enables exceptions by passing true to the constructor and reports failures with ErrorInfo in the catch block. Without that, you see nothing.

grep -rn "new PHPMailer" .

2Fix

Pass true to the constructor, wrap send() in try and catch, and print ErrorInfo. Set SMTPDebug to SMTP::DEBUG_SERVER, level 2, which shows client and server messages.

$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;

3Verify

A failed send now prints the reason and the SMTP replies.

php send-test.php

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

isSMTP() was not called, so mail() is used

1Check

The PHPMailer troubleshooting page lists 'Could not instantiate mail function' for a mail() setup that is not configured correctly. SMTP settings only apply when you select SMTP.

grep -n "isSMTP\|Host" send-test.php

2Fix

Select SMTP and set host, port and credentials.

$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'your-login';
$mail->Password = 'your-app-password';

3Verify

Debug output now begins with a connection to your SMTP host.

php send-test.php

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The encryption mode and the port do not match

1Check

The README pairs ENCRYPTION_STARTTLS with port 587, and ENCRYPTION_SMTPS, implicit TLS, with port 465.

grep -n "SMTPSecure\|Port" send-test.php

2Fix

Choose one valid pair.

$mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

3Verify

The debug output shows the server accepting the login and the message.

php send-test.php

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Keep SMTPDebug at 0 in production, and log ErrorInfo instead.
  • Always catch PHPMailer exceptions and write them to your log.
  • Send a test mail after every host or password change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.