I've used PHPMailer on several projects but now I'm stuck. It gives me the error:
SMTP Error: Could not connect to SMTP host.
I've tried sending email from Thunderbird and it works ! But not through PHPMailer ... Here are the settings from Thunderbird:
Server name: mail.exampleserver.com
Port: 587
Username: user@exampleserver.com
Secure Authentication: No
Connection Security: STARTTLS
I've compared these with the server at my last project where I used PHPMailer and they were:
Server name: mail.exampleserver2.com
Port: 465
Username: user@exampleserver2.com
Secure Authentication: No
Connection Security: SSL/TLS
My php code is:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = SMTP_HOST; // SMTP servers
$mail->Port = SMTP_PORT; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password
$mail->From = MAIL_SYSTEM;
$mail->FromName = MAIL_SYSTEM_NAME;
$mail->AddAddress($aSecuredGetRequest['email']);
$mail->IsHTML(true); // send as HTML
Where I am wrong?
I had a similar issue and figured out that it was the
openssl.cafile
configuration directive inphp.ini
that needed to be set to allow verification of secure peers. You just set it to the location of a certificate authority file like the one you can get at http://curl.haxx.se/docs/caextract.html.This directive is new as of PHP 5.6 so this caught me off guard when upgrading from PHP 5.5.
Since this questions shows up high in google, I'd like to share here my solution for the case where PHP was just upgraded to version 5.6 (which has stricter SSL behavior).
The PHPMailer wiki has a section on this:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure
The suggested workaround is including the following piece of code:
This should work for PHPMailer 5.2.10 (and up).
Note: Obviously, and also as suggested in that wiki, this should be a temporary solution!
Since this is a popular error, check out the PHPMailer Wiki on troubleshooting.
Also this worked for me
does mail.exampleserver.com exist ??? , if not try the following code (you must have gmail account)
Followed code worked for me:
I had the same problem and it was because PHPMailer realized the server supported STARTTLS so it tried to automatically upgrade the connection to an encrypted connection. My mail server is on the same subnet as the web server within my network which is all behind our domain firewalls so I'm not too worried about using encryption (plus the generated emails don't contain sensitive data anyway).
So what I went ahead and did was change the SMTPAutoTLS to false in the class.phpmailer.php file.