Azkatro
Azkatro

Reputation: 63

SMTP relay not working on PHPMailer 6.0.5

I'm using PHPMailer to send email via SMTP relay from my platform to send email. I've configured the authentication and everything, and also successfully sent test emails from the command line mail program on my server.

Initially, I had configured the SMTP relay via Postfix config and aimed to use the PHP mail() function. This was working fine from basic test scripts, but from my platform software, the emails were disappearing, despite the Postfix log saying the mail was relayed out successfully.

I replaced the usage of the mail() function with the latest version of PHPMailer, however the issue persists. I have captured a full log of a test send as an example:

2018-05-11 00:32:42 Connection: opening to smtp.api.createsend.com:587, timeout=300, options=array()
2018-05-11 00:32:43 Connection: opened
2018-05-11 00:32:43 SMTP INBOUND: "220 smtp.api.createsend.com ESMTP"
2018-05-11 00:32:43 SERVER -> CLIENT: 220 smtp.api.createsend.com ESMTP 
2018-05-11 00:32:43 CLIENT -> SERVER: EHLO localhost
2018-05-11 00:32:43 SMTP INBOUND: "250-Hello smtp.api.createsend.com[1.129.185.25]"
2018-05-11 00:32:43 SMTP INBOUND: "250-PIPELINING"
2018-05-11 00:32:43 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2018-05-11 00:32:43 SMTP INBOUND: "250-8BITMIME"
2018-05-11 00:32:43 SMTP INBOUND: "250-STARTTLS"
2018-05-11 00:32:43 SMTP INBOUND: "250-AUTH PLAIN LOGIN"
2018-05-11 00:32:43 SMTP INBOUND: "250-AUTH=PLAIN LOGIN"
2018-05-11 00:32:43 SMTP INBOUND: "250 SIZE 20971520"
2018-05-11 00:32:43 SERVER -> CLIENT: 250-Hello smtp.api.createsend.com[1.129.185.25]250-PIPELINING250-ENHANCEDSTATUSCODES250-8BITMIME250-STARTTLS250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250 SIZE 20971520
2018-05-11 00:32:43 CLIENT -> SERVER: STARTTLS
2018-05-11 00:32:43 SMTP INBOUND: "220 2.0.0 Ready to start TLS"
2018-05-11 00:32:43 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-05-11 00:32:43 CLIENT -> SERVER: EHLO localhost
2018-05-11 00:32:43 SMTP INBOUND: "250-Hello smtp.api.createsend.com[1.129.185.25]"
2018-05-11 00:32:43 SMTP INBOUND: "250-PIPELINING"
2018-05-11 00:32:43 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2018-05-11 00:32:43 SMTP INBOUND: "250-8BITMIME"
2018-05-11 00:32:43 SMTP INBOUND: "250-AUTH PLAIN LOGIN"
2018-05-11 00:32:43 SMTP INBOUND: "250-AUTH=PLAIN LOGIN"
2018-05-11 00:32:43 SMTP INBOUND: "250 SIZE 20971520"
2018-05-11 00:32:43 SERVER -> CLIENT: 250-Hello smtp.api.createsend.com[1.129.185.25]250-PIPELINING250-ENHANCEDSTATUSCODES250-8BITMIME250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250 SIZE 20971520
2018-05-11 00:32:43 Auth method requested: UNSPECIFIED
2018-05-11 00:32:43 Auth methods available on the server: PLAIN,LOGIN
2018-05-11 00:32:43 Requested auth method not available: 
2018-05-11 00:32:43 Auth method selected: LOGIN
2018-05-11 00:32:43 CLIENT -> SERVER: AUTH LOGIN
<snip>
2018-05-11 00:32:43 SMTP INBOUND: "235 2.7.0 Authentication successful"
2018-05-11 00:32:43 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2018-05-11 00:32:43 CLIENT -> SERVER: MAIL FROM:<###envelope_from_email_address@domain1###>
2018-05-11 00:32:43 SMTP INBOUND: "250 2.1.0 accepting mail from <###envelope_from_email_address@domain1###> OK"
2018-05-11 00:32:43 SERVER -> CLIENT: 250 2.1.0 accepting mail from <###envelope_from_email_address@domain1###> OK
2018-05-11 00:32:43 CLIENT -> SERVER: RCPT TO:<###to_email_address@domain2###>
2018-05-11 00:32:43 SMTP INBOUND: "250 2.1.0 I'll make sure <###to_email_address@domain2###> gets this"
2018-05-11 00:32:43 SERVER -> CLIENT: 250 2.1.0 I'll make sure <###to_email_address@domain2###> gets this
2018-05-11 00:32:43 CLIENT -> SERVER: DATA
2018-05-11 00:32:43 SMTP INBOUND: "354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF>"
2018-05-11 00:32:43 SERVER -> CLIENT: 354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF>
2018-05-11 00:32:43 CLIENT -> SERVER: Date: Fri, 11 May 2018 10:32:42 +1000
2018-05-11 00:32:43 CLIENT -> SERVER: To: ###to_email_address@domain2###
2018-05-11 00:32:43 CLIENT -> SERVER: From: ###from_email_address@domain3###
2018-05-11 00:32:43 CLIENT -> SERVER: Subject: ###email_subject###
2018-05-11 00:32:43 CLIENT -> SERVER: Message-ID: <0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA@localhost>
2018-05-11 00:32:43 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2018-05-11 00:32:43 CLIENT -> SERVER: MIME-Version: 1.0
2018-05-11 00:32:43 CLIENT -> SERVER: Content-Type: multipart/alternative;
2018-05-11 00:32:43 CLIENT -> SERVER: boundary="b1_0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA"
2018-05-11 00:32:43 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: This is a multi-part message in MIME format.
2018-05-11 00:32:43 CLIENT -> SERVER: --b1_0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA
2018-05-11 00:32:43 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: 
<snip for plaintext email content>
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: --b1_0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA
2018-05-11 00:32:43 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2018-05-11 00:32:43 CLIENT -> SERVER: 
<snip for html email content>
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: --b1_0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA--
2018-05-11 00:32:43 CLIENT -> SERVER: 
2018-05-11 00:32:43 CLIENT -> SERVER: .
2018-05-11 00:32:43 SMTP INBOUND: "250 2.0.0 OK:ODJmM2I5YmEtMzU0My00M2ZjLWE5NzUtNTlkNzNkMjE0N2Ew"
2018-05-11 00:32:43 SERVER -> CLIENT: 250 2.0.0 OK:ODJmM2I5YmEtMzU0My00M2ZjLWE5NzUtNTlkNzNkMjE0N2Ew
2018-05-11 00:32:43 CLIENT -> SERVER: QUIT
2018-05-11 00:32:43 SMTP INBOUND: "221 2.0.0 Bye"
2018-05-11 00:32:43 SERVER -> CLIENT: 221 2.0.0 Bye
2018-05-11 00:32:43 Connection: closed

As it shows, PHPMailer successfully connects and authenticates using TLS, sends the email content, signs off without a hitch. However, this (and many other similar examples) don't appear in the SMTP provider's delivery logs. Additionally, I've been told by their customer support that these emails are never hitting their servers. Example response (this response was based on the above log):

Thank you for following up here, I'm afraid we don't have detailed enough logs to provide further information on this. Also, I can't see from the information you provided that we are responding with a message ID, I believe the message ID that appears in your log is generated by PHP Mailer and is not related to Campaign Monitor. I don't believe our server is responding to this attempt to send an email, which would indicate that the problem is with your implementation of PHP Mailer.

As the provider says, the issue here is with PHP Mailer. That doesn't make sense at all to me based on the logs, but I don't know enough to be able to diagnose what's going wrong and why these emails are disappearing. How can I troubleshoot the problem?

Upvotes: 1

Views: 1536

Answers (1)

Synchro
Synchro

Reputation: 37770

This delivery is entirely successful. Any issues after that are not down to your sending code. To find out what happened to the message, you would need to look at the mail logs on smtp.api.createsend.com (which is apparently Campaign Monitor).

PHPMailer creates the Message-ID header, as it should, since it's the responsibility of the MUA, in this case 0JtQSmGxTN2PuNR4zJx5iqS9FyZrLK5gL3zPLHwVCA@localhost, and you could improve this. It's falling back to localhost as the hostname, which suggests PHP on your server is not configured correctly and doesn't know its own hostname. You can either fix that in your PHP config, or set $mail->MessageID yourself (note the pattern that it must match).

The SMTP transaction ID (in this case ODJmM2I5YmEtMzU0My00M2ZjLWE5NzUtNTlkNzNkMjE0N2Ew), which is not the same as the message ID, is created by the receiving server and is usually used for internal tracking by the receiving server.

Incidentally it's the first time I've seen Campaign Monitor's transaction ID pattern, and it's different to others, so I've added it to PHPMailer. You will be able to retrieve it after sending by calling $mail->smtp->getLastTransactionID().

Upvotes: 0

Related Questions