PHPMailer runs without an error, but no email arrives
No exception, no output, and no emailShort 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.
Fix it fast
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}"; }2Match what you see, then jump to its fix
- 1
Your script prints its own success line even though no mail was sent.Errors are never reported because exceptions and debug are offFix - 2
Could not instantiate mail function, or no SMTP lines appear in the debug output at all.isSMTP() was not called, so mail() is usedFix - 3
The debug output stops after the connection, or the server closes it.The encryption mode and the port do not matchFix
- 1
What does the error look like?
No exception, no output, and no emailMessage 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.phpConfirmed by raw.githubusercontent.com
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.php2Fix
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.phpConfirmed by github.com
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.php2Fix
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.phpConfirmed by raw.githubusercontent.com
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
PHPMailer fails with 'certificate verify failed' when connecting to the SMTP server
OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
PHPMailer checks the mail server's certificate and the check failed.
3 causes, each with a fixCodeIgniter email does not send and shows no error message
$email->printDebugger() prints an empty result
CodeIgniter signals a failed email only by send() returning false, with no exception.
4 causes, each with a fixLaravel tries to send mail to mailpit:1025 instead of your real SMTP server
Symfony\Component\Mailer\Exception\TransportException
Laravel is still using the development mail host from the starter .env, mailpit on port 1025, which only exists inside Laravel Sail.
3 causes, each with a fixLaravel mail fails because an address does not comply with RFC 2822
Email "Jane Doe <jane@example.com>" does not comply with addr-spec of RFC 2822.
Symfony Mailer checks every address when the Address object is created.
3 causes, each with a fixLaravel says the email was sent, but nothing arrives
Mail::to($user)->send() returns normally
Mail::send returns without an error when the message was accepted by the configured mailer, not when it was delivered.
3 causes, each with a fixLaravel mail fails with 'Unable to connect with STARTTLS' and SSL operation failed with code 1
stream_socket_enable_crypto(): Peer certificate verification failed
The mail server offered STARTTLS, but PHP could not verify the certificate it presented.
3 causes, each with a fix