【问题标题】:Not receiving emails from phpmailer and cpanel未收到来自 phpmailer 和 cpanel 的电子邮件
【发布时间】:2019-02-25 05:35:30
【问题描述】:

所以我有一个使用 phpmailer 的联系表。它从一个 Gmail 帐户向另一个帐户发送电子邮件。但我似乎无法让接收电子邮件接收任何电子邮件。

脚本托管在 cpanel (RivalHost) 上,域在 GoDaddy 上。我问 RivalHost 他们是阻止 SMTP 连接还是阻止端口 587 或 465,他们说没有。所以我不知道是什么导致了这个问题。该脚本在我的本地主机上运行得很好,只是在 cpanel 上没有

这是邮件脚本:

<?php

$result="";

if(isset($_POST['submit'])){
    require 'phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;

    $mail->Host='smtp.gmail.com';
    $mail->Port=465;
    $mail->SMTPAuth=true;
    $mail->SMPTSecure='ssl';
    $mail->Username='sendingemail@gmail.com';
    $mail->Password='*********';

    $mail->setFrom('sendingemail@gmail.com');
    $mail->addAddress('receivingemail@gmail.com');
    $mail->addReplyTo($_POST['email'],$_POST['name']);

    $mail->isHTML(true);
    $mail->Subject='Contact: '.$_POST['subject'];
    $mail->Body='Message: '.$_POST['msg'].'</h1>';

    if(!$mail->send()){
        $result='something went wrong';
        echo $result;


    } else {
        $result="thank you";
        echo $result;
    }
}

?>

我还被告知要检查我的 MX 记录,但不确定将它们更改为什么,或者我是否需要更改它们:

MX  0   ********.com    3599    RBL

【问题讨论】:

  • 设置SMTPDebug = 2 并查看调试输出。这将确认您的消息正在发送。如果是,请检查您的垃圾邮件文件夹。另外,您使用的是旧版本的 PHPMailer,因此请升级。

标签: php smtp phpmailer cpanel


【解决方案1】:

解决方案 1: PHPMailer 使用例外。您可以将代码放在 try/catch 块中,以获取导致电子邮件无法发送的异常。

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

try {
  //Email information comes here
  $mail->Send();
  echo "Message Sent OK\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
}

解决方案 2: 您是否也在使用 CSF 防火墙?如果是这样,请检查是否启用了“SMTP_BLOCK”设置。如果STMP_BLOCK 是启用联系到主机禁用它。

【讨论】:

  • 添加了您的代码,没有返回任何错误。它返回消息发送正常,但仍然没有收到电子邮件
【解决方案2】:

将此添加到您的设置中:

$mail->isSMTP();
$mail->SMTPDebug = 2; 
$mail->SMTPAuth = true;
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message sent!';
}

【讨论】:

    猜你喜欢
    • 2019-07-22
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    相关资源
    最近更新 更多