Search code examples
sslnginxsmtpcloudflare

PHPMailer verify peer SSL


Full code below. If i change verify_peer to true it will return SMTP ERROR: Failed to connect to server: (0). But SSL have been installed already. You can check it here How to solve this? i dont want to skip verifying peer. Server nginx. (CLOUDFLARE SSL)

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.mail.ru";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username   = "somemail@mail.ru"; // SMTP account username example
$mail->Password   = "somepass";        // SMTP account password example
$mail->SetFrom("somemail@mail.ru");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("somemail2@mail.ru");
$mail->SMTPOptions = array (
    'ssl' => array (
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}

Solution

  • The solution is change the autosigned SSL Certificate to support SNI. You would have to ask to your hosting provider about that.

    Regards