Can PHPMailer determine the precise reason for SMTP failure? - php

I'm currently writing a tool that helps users configure an SMTP send, and am using PHPMailer to achieve this. Presently I notify users if the SMTP operation was not successful, and I'd like to make this more specific.
In the source code, it says:
// The reason for failing to send will be in $mail->ErrorInfo
However, the contents of this property are not very specific. For example, for both a failed auth and an unreachable server, I get the identical error:
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
However, if I dig into the SMTP logs using PHPMailer's debug level 2, I get more useful information. For a failed auth:
2018-01-31 19:37:12 SERVER -> CLIENT: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2018-01-31 19:37:12 SMTP Error: Could not authenticate.
For an unreachable server:
2018-01-31 21:12:34 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
So, it looks like this information is available, but it might vary between different mail server types. Is there any parsing of this in PHPMailer? I'd like reliable reason codes I can test, rather than searching for strings in logs that might not match for every server.
I expect there are other failure types as well, such as a badly configured certificate.

Related

How do I get fix the SMTP Error: data not accepted error?

I am trying to send mass e-mails via PHPList software with the Direct Mail service in Alibaba Cloud, but I am getting the error below.
Error sending email to email#gmail.com SMTP Error: data not accepted.SMTP server error: DATA command failed Detail: Invalid rcptto [#sm070102] at DATA State(Connection IP address:111.111.11.11) ANTISPAM_BAT[01201311R166c, ay35sg011193009126]: invaddr reject SMTP code: 559
What should I do to fix this problem?

imap_open(): Couldn't open stream for hostgator server {mail.mydomain.com:993/imap/ssl}INBOX in codeigniter

I am working in codeigniter framework using imap library. I want to get all mails from my mail server into my web app.
My code is working fine when i am using
imap_open("{imap.gmail.com:993/imap/ssl}INBOX", my_email, my_password);
but whenever I tried to get access of my hostgator mail server I got these type of errors.
1: imap_open(): Couldn't open stream {mail.mydomain.com:993/imap/ssl}INBOX
2: Retrying PLAIN authentication after [AUTHENTICATIONFAILED] Authentication failed. (errflg=1).
3: Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Authentication failed. (errflg=2)
According the HostGator Documentation you should provide (for secured imap):
A username, your full email address
Your password
Your full server name
Port: 993
SSL: SSL/TLS
You should end up with something like
imap_open("{full.servername.com:993/imap/ssl/tls}", "my.email#servername.com","pwd");
You could also try the normal incoming mail settings which requires
A username, your full email address
Your password
Your full server name
Port: 143
SSL: none
Resulting in:
imap_open("{full.servername.com:143}", "my.email#servername.com","pwd");

PHPMailer EOF caught while checking if connected

We've been using PHPMailer to send SMTP mail through Mailgun for years now.
We've recently upgraded our logging, and we've noticed that some mail just doesn't send.
Here is the SMTP log we're seeing:
Connection: opening to smtp.mailgun.org:587, timeout=300, options=array()
Connection: opened
SERVER -> CLIENT: SMTP
NOTICE: EOF caught while checking if connected
Connection: closed
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.
This particular email was attempted to be sent with the Start TLS method via port 587.
How come most of our mail gets through but now and then we get this error?
Does anyone know what "EOF caught while checking if connected" could be caused by?
We're using the latest stable build of PHPMailer v6.1.5.
Thanks!
Thanks to advice from #Syncro and #Álvaro González and Mailgun themselves, I ended up building in a retry mechanism that attempts to send mail 3 times before failing.
So far this seems to be working, I will report back if anything changes!

Mail is not sent every time by swiftmailer using office365

Smtp details which we use are correct, for host smtp.office365.com mail is not sent every time.
Sometimes this error is generated,
Fatal error: Uncaught Swift_TransportException: Failed to authenticate on SMTP server with username "XXX" using 2 possible authenticators in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 181
Observed behaviour
Sometimes with the same details, emails are sent.
Expected behaviour
It should send an email every time.
Can anyone please tell me what should I do?
Is the login credentials you used correct and the.env file configured correctly? Here are two links that might be useful to you.
PHP Fatal error: 'Swift_TransportException' with message 'Failed to authenticate on SMTP server
Failed to authenticate on SMTP server error using gmail

SMTP Error 535 (Incorrect authentication data) using PEAR mail

I used the code from https://stackoverflow.com/a/2748837 to attempt to log into both Gmail and my website's server, and for both of them I received the same error:
authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]
I have double- and triple-checked that the usernames and passwords are correct (since it works from a desktop client), and removed the brackets around the username. What could be the problem?

Categories