0

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';
Syriusz
  • 11
  • 1
  • 1
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – nyedidikeke Aug 26 '21 at 11:22
  • @nyedidikeke 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. it's a nightmare – Syriusz Aug 26 '21 at 12:01
  • Hi. Check if your SSL is correctly configured in your local environment. Also check if you have the PHP OpenSSL extension enabled, you can check if it's enabled with `php -m` command :) – Adriana Hernández Aug 26 '21 at 12:27
  • @Adriana Hernández `OpenSSL support => enabled OpenSSL Library Version => OpenSSL 1.1.1f 31 Mar 2020 ` – Syriusz Aug 26 '21 at 12:36
  • Just for testing, try putting this line in your php.ini `openssl.cafile=/etc/ssl/certs/ca-certificates.crt` (of course check if that file in that directory exists or put another one crt file that exist) - I solved a similar issue by doing that :/ – Adriana Hernández Aug 26 '21 at 12:42

0 Answers0