1

I am using PHPMailer to connect to a remote smtp server running Exim. In my exim logs, I can see that the sending failed, but PHPMailer does not catch an exception and it seems like the SMTP server is returning an "Ok" status.

Here is the excerpt from my exim log:

2019-06-27 17:03:00 1hgbXj-0000O5-Vl == *******@gmail.com R=dnslookup T=remote_smtp defer (-44) H=alt4.gmail-smtp-in.l.google.com [108.177.119.27]: SMTP error from remote mail server after RCPT TO:<********@gmail.com>: 452-4.2.2 The email account that you tried to reach is over quota. Please direct\n452-4.2.2 the recipient to\n452 4.2.2  https://support.google.com/mail/?p=OverQuotaTemp **** - gsmtp

And here is the (end of the) PHPMailer debug output:

SERVER -> CLIENT: 250 OK id=1hgbf8-0008CL-15
CLIENT -> SERVER: RSET
SERVER -> CLIENT: 250 Reset OK
Done @0.0734977722168s
CLIENT -> SERVER: QUIT

Any way I can see this error in PHP so that I can log the error in my application?

danielb
  • 878
  • 4
  • 10
  • 26

1 Answers1

1

This is nothing to do with PHPMailer. The PHPMailer debug output shows a successful delivery to your exim server. That's where its involvement ends - at no point does PHPMailer talk to gmail, and so never sees this response.

Exim (as intended) then goes on to try to deliver the message, but receives a failure notice from gmail. What you should then see in your logs is an attempt by exim to bounce the message to the return path, which is set by your mail server from the SMTP envelope sender used to submit the original message. You can control this address by setting the Sender property in PHPMailer, though it defaults to your from address, which is what you'd usually want.

If you want to hear about these bounces in your code instead of your mailbox, you need to get exim to pipe them to a script rather than a mailbox, and this is something that exim is quite happy to do.

Bounce handling is not a pleasant thing to write, but you may find that using VERP addressing helps.

Synchro
  • 35,538
  • 15
  • 81
  • 104