CodeIgniter email does not send and shows no error message
$email->send() returns false and nothing else happensShort answer
CodeIgniter signals a failed email only by send() returning false, with no exception. Call send(false) so the debugger data is kept, print printDebugger(), then check the protocol, the SMTPPort and SMTPCrypto pair, and the 5-second SMTPTimeout.
Fix it fast
1Find out which cause you have
Send without clearing the message data, then print the debugger. Without false, the data is cleared and there is nothing to print.
if (! $email->send(false)) { echo $email->printDebugger(['headers']); }2Match what you see, then jump to its fix
- 1
printDebugger returns almost nothing, so you cannot see the server reply.send() cleared the data before printDebugger ranFix - 2
SMTP settings are in your config but the debugger shows no SMTP conversation.The protocol is still the default mail()Fix - 3
The attempt fails or times out right at the connection.SMTPCrypto does not match the portFix - 4
Failures appear only on some sends, mostly with a slow relay.SMTPTimeout of 5 seconds is too short for a slow serverFix
- 1
What does the error look like?
$email->send() returns false and nothing else happens$email->printDebugger() prints an empty result
Cause 1 of 4
send() cleared the data before printDebugger ran
1Check
By default a successful or attempted send clears all email parameters. The documentation says to call send(false) first, or there is nothing to print.
grep -rn "printDebugger" app/2Fix
Use send(false) while debugging and read the server messages the debugger returns.
$sent = $email->send(false);
if (! $sent) {
log_message('error', $email->printDebugger(['headers', 'subject']));
}3Verify
The log now contains the SMTP server messages for the failed attempt.
tail -n 40 writable/logs/log-$(date +%F).logConfirmed by codeigniter.com
Cause 2 of 4
The protocol is still the default mail()
1Check
The protocol preference defaults to mail. SMTPHost, SMTPUser and the other SMTP values are only used when protocol is smtp.
grep -n "protocol\|SMTPHost" app/Config/Email.php2Fix
Set the protocol to smtp in app/Config/Email.php, or pass it to initialize().
public string $protocol = 'smtp';
public string $SMTPHost = 'smtp.example.com';
public int $SMTPPort = 587;3Verify
Send again and read the debugger. It now shows the SMTP server replies.
grep -n "protocol" app/Config/Email.phpConfirmed by codeigniter.com
Cause 3 of 4
SMTPCrypto does not match the port
1Check
SMTPPort defaults to 25. Port 465 uses TLS regardless of SMTPCrypto, and the documentation says port 465 should use an empty SMTPCrypto. Port 587 usually uses tls, which issues STARTTLS.
grep -n "SMTPPort\|SMTPCrypto" app/Config/Email.php2Fix
Pair the port with the right crypto value.
// port 587
public int $SMTPPort = 587;
public string $SMTPCrypto = 'tls';
// or port 465
public int $SMTPPort = 465;
public string $SMTPCrypto = '';3Verify
send(false) returns true.
grep -n "SMTPCrypto" app/Config/Email.phpConfirmed by codeigniter.com
Cause 4 of 4
SMTPTimeout of 5 seconds is too short for a slow server
1Check
SMTPTimeout defaults to 5 seconds.
grep -n "SMTPTimeout" app/Config/Email.php2Fix
Raise the timeout a little. Do not set it so high that a web request hangs.
public int $SMTPTimeout = 15;3Verify
Repeat the send that failed.
grep -n "SMTPTimeout" app/Config/Email.phpConfirmed by codeigniter.com
How do I stop it coming back?
- Always test the return value of send() and log printDebugger() on failure.
- Keep the port and SMTPCrypto pair in one config file, not scattered through controllers.
- Send long mail jobs from a queue, not inside a web request.
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
Laravel 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 fixPHP mail() returns true but the email never arrives
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing
mail() returning true only means the message was accepted for delivery, not that it arrived.
4 causes, each with a fixPHPMailer addCC() adds no CC recipient
The mail arrives for the To address but not for the CC address
addCC() returns false when it rejects the address, and PHPMailer then sends without that CC.
3 causes, each with a fix