Debian Linux Phpmailer: EOF Caught while checking if Connected

Asked

Viewed 228 times

0

Hello! I’m having a problem using Phpmailer for an email sending via 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 Debian Linux VPS. When I run on Localhost on my Windows, the script works normally.

I’m using Zohomail’s SMTP, but I’ve tried it with Gmail as well, 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 ports. VPS is from OVH. Error log posted here: https://pastebin.com/Z734ZEws

  • Which version of TLS on the email server and which version of PHP on your HTTP server?

  • @Guilhermenascimento, the email server I have no knowledge of. But I was using Google’s TLS server as well. Already the PHP version is 7.0

  • Just for the record, on the php.net website they encourage you not to use php7.0 ... but more recent versions, it might be a bug so.

1 answer

0

As I ran out of options, I decided to install the latest version of Phpmailer (https://github.com/PHPMailer/PHPMailer) even without Composer, I was able to make SSL work, as well as TLS on localhost. However, both of them were still a problem in my VPS.

However, with this new version, I was able to debug better and look where the bug was, and apparently it’s because it couldn’t authenticate SSL security. Searching a little deeper 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: Is working with SSL version in VPS.

  • Then you "shut off" the security :/

  • So what do you recommend, @Guilhermenascimento? (Even with PHP 7.2 still giving trouble, so it’s really no problem in PHP version)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.