class.phpmailer.php 在 000webhost.com 中返回 SMTP connect() 失败错误


class.phpmailer.php returns SMTP connect() failed error in 000webhost.com

我使用class.phpmailer.php发送确认电子邮件。它在我的本地服务器中运行良好,但是当我将其上传到000webhost.com的服务器时,它不再工作。我刚刚发现mail()也不再工作了。我能做些什么来解决这个问题吗?以下是我用来发送系统中每封邮件的函数的代码: code

function correoEnviar($asunto, $mensaje, $mensajeTexto, $email)
{
    $mail = new PHPMailer;
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.mail.yahoo.com';  // Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'xxxx@yahoo.com.mx';                            // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    $mail->From = 'xxxx@yahoo.com.mx';
    $mail->FromName = 'xxxx';
    $mail->addAddress($email);               // Name is optional
    $mail->addReplyTo('xxxx@yahoo.com.mx', 'Information');
    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    $mail->isHTML(true);                                  // Set email format to HTML
    //$mail->Subject = 'Por favor confirme su correo para obtener el libro El fractal y el =?UTF-8?Q?dise=C3=B1o=C2=A0gr=C3=A1fico?=';
    $mail->Subject = $asunto;
    $mail->Body    = $mensaje;
    $mail->AltBody = $mensajeTexto;
    if(!$mail->send()) {
        return $mail->ErrorInfo;
    }
    else
        return 1;
}
echo correoEnviar($asunto, $mensaje, $mensajeTexto, "recipent@gmail.com");

?> code

你确定你包含的是文件class.phpmailer.php,你的代码看起来很好。

粘贴服务器的邮件服务器日志,它将提供更好的洞察力。

您的代码很好,可能是服务器问题。

显示 SMTP 设置的示例代码

require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->SMTPAuth = true;     // turn of SMTP authentication
$mail->Username = "YAHOO ACCOUNT";  // SMTP username
$mail->Password = "YAHOO ACCOUNT PASSWORD"; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Host = "YAHOO HOST"; // SMTP host
$mail->Port = 465;