PHPMailer Linux Debian: EOF caught while checking if connected

0

Hello! I'm having a problem using PHPMailer to send an email through an external SMTP.

When I try to run the code, it always shows the following error at the end:

  

SMTP - > NOTICE: EOF caught while checking if connectedThe following From address failed: [email protected]: Called Mail () without being connected Mail error: The following From address failed: [email protected]: Called Mail () without being connected

However, this only happens when I am using a Linux Debian VPS. When I run on Localhost on my Windows, the script works normally.

I'm using ZohoMail's SMTP, but I already tried with GMail's, too, they both work localhost, but none works on the machine.

require_once("phpmailer/class.phpmailer.php");


function smtpmailer($para, $de, $de_nome, $assunto, $corpo) { 
    global $error;
    $mail = new PHPMailer();
    $mail->IsSMTP();        // Ativar SMTP
    $mail->SMTPDebug = 2;       // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
    $mail->SMTPAuth = true;     // Autenticação ativada
    $mail->SMTPSecure = 'tls';  // TLS REQUERIDO
    $mail->Host = 'smtp.zoho.com';  // SMTP utilizado
    $mail->Port = 587;          // A porta 587 deverá estar aberta em seu servidor
    $mail->Username = "[email protected]";
    $mail->Password = "senha";
    $mail->SetFrom($de, $de_nome);
    $mail->Subject = $assunto;
    $mail->Body = $corpo;
    $mail->AddAddress($para);
    $mail->Sendmail     = '/usr/sbin/sendmail';
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Mensagem enviada!';
        return true;
    }
}

Firewall is disabled. I am using the correct TLS method ports. The VPS is from the OVH company. The error log posted here: link

    
asked by anonymous 05.09.2018 / 04:35

1 answer

0

As I ran out of options, I decided to install the latest version of PHPMailer ( link ) even without the composer, I was able to run SSL , and also the TLS on localhost. However, both still messed up problem in my VPS.

However, with this new version, I was able to debug better and look where the error was, and apparently it was because it could not authenticate SSL security. Searching a little further on the internet, I found this solution, where you put this parameter / array:

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => false,
            "verify_peer_name" => false,
            "allow_self_signed" => true
        )
    )
);

And everything works perfectly, as it should. =) PS: It's working with the SSL version in VPS.

    
05.09.2018 / 19:22