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