Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer SMTP localhost, certificate error

We use PHPMailer. The server is configured to use the local SMTP. So, the general PHPMailer commando looks like this:

$mail = new PHPMailer();
$mail->From = '[email protected]';
$mail->Host = 'localhost';
$mail->IsSMTP();
...

Since PHP5.6, this doesn't work anymore, because the certificate does not match. We get the following error:

Warning: stream_socket_enable_crypto(): Peer certificate CN='*.thisvps.com' did not match expected CN='localhost' in /ho...PHPMailer_latest/class.smtp.php

I can suppress this error using:

$this->smtpConnect([
   'ssl' => [
       'verify_peer' => false,
       'verify_peer_name' => false,
       'allow_self_signed' => true
   ]
]);

But, is that the correct way to go? I'm not a big fan of suppressing errors;). Or maybe there is an error in our configuration?

Version info: PHP 5.6.30, PHPMailer: 5.2.21

Any suggestion are welcome, thanks in advance!

like image 901
sanderbee Avatar asked Feb 15 '26 04:02

sanderbee


1 Answers

It's odd that you're getting that cert from the server if it's not something you have configured. It could be down to your ISP redirecting your traffic, though I wouldn't expect that to affect localhost.

You can turn off encryption altogether (it's safe to localhost as there's no external network traffic) with $mail->SMTPSecure = false;, though you may need to also set $mail->SMTPAutoTLS = false; to prevent it being re-enabled automatically if your server advertises STARTTLS.

Alternatively, this host presumably has a hostname in the thisvps.com domain that you could use, and then the name would match the cert.

like image 117
Synchro Avatar answered Feb 16 '26 17:02

Synchro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!