I am using PHPMailer to send an newsletter email's from my website, locally (http://localhost) its works properly but on my online server (https://example.net) I got an error:
My php version PHP 7.4.3
My phpmailer version 5.2.27
2021-08-26 10:20:03 Connection: opening to ssl://smtp.trol.pl:465, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2021-08-26 10:20:03 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol [/var/www/example.net/public/staff/news/email_7/smtp/class.smtp.php line 298]
2021-08-26 10:20:03 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/var/www/example.net/public/staff/news/email_7/smtp/class.smtp.php line 298]
2021-08-26 10:20:03 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.trol.pl:465 (Unknown error) [/var/www/example.net/public/staff/news/email_7/smtp/class.smtp.php line 298]
My PHP code:
function smtp_mailer($to,$subject,$msg) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = "UTF-8";
$mail->SetFrom("newsletter@example.net");
$mail->Host = "smtp.trol.pl";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->Username = "newsletter-xxxx";
$mail->Password = 'xxxxxx';
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->SMTPDebug = 3;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
if(!$mail->Send()){
echo $mail->ErrorInfo;
}else{
echo 'Sent';
}
}
I added new google user, and it works, it looks like it's the mail server provider's fault, but he tells me it's phpmailer fault.
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->CharSet = 'UTF-8';
$mail->Username = "googleuser";
$mail->Password = 'passwdxxxx';