I've used PHPMailer on several projects, but now I'm stuck. It gives me the error:
SMTP Error: Unable to connect to SMTP host.
I tried sending email from Thunderbird and it worked! But not through PHPMailer... Here are the settings for Thunderbird:
Server name: mail.exampleserver.com
Port: 587
Username: user@exampleserver.com
Secure Authentication: No
Connection Security: STARTTLS
I compared them to the server from my last project using PHPMailer and they are:
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 did I go wrong?
P粉3524080382023-10-13 14:23:02
Since this question comes up so frequently in google, I wanted to share here my solution for a situation where PHP has just been upgraded to version 5.6 (which has stricter SSL behavior).
The PHPMailer wiki has a section about this:
https://github.com/PHPMailer/ PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure
Suggested workarounds include the following code:
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );
This should work with PHPMailer 5.2.10 (and later).
NOTE: Apparently, as suggested in this wiki, this should be a temporary solution!