php邮件脚本无法使用phpMailer工作

问题描述 投票:1回答:1

我正在使用phpMailer使用PHP发送电子邮件。邮件正在发送但收件箱/垃圾邮件或其他任何内容都没有收到。令人惊讶的是它在几天前才开始工作。我测试了它,发送和接收了近500-600封电子邮件。但突然它停止了“工作”。

这是我的Php脚本:

public static function mailTo($recipients)
{
    $f3 = \Base::instance();
    $edit = $f3->get('editTrue');
    $user = AclHelper::getCurrentUser();
    $template= new \Template;
    if(isset($edit))
    {
        $mailBody = $template->render('leave/requestEdit.html');
    }
    else
    {
        $mailBody= $template->render('leave/emailTemp.html');
    }

    // When true, PHPMailer returns exceptions
    $mail = new PHPMailer(true);
    try {
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->isHTML(true);

        $mail->addAddress($user['email']);
        $mail->addAddress("[email protected]");

        // foreach($recipients as $recipient){
        //     $mail->addCC($recipient);
        // }

        $mail->SMTPAuth = true; // authentication enabled
        $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 465; // or 587
        $mail->Username = "[email protected]";
        $mail->Password = "abcd";

        // $mail->Host = $f3->get('GBD.smtp.host');   // Specify main and backup SMTP servers
        $mail->setFrom($user['email']);

        $userFullName = trim(ucfirst($user['firstname'])) . " " . trim(ucfirst($user['lastname']));
        $mail->FromName = $userFullName;
        $mail->Body =  $f3->get('message');
        $mail->Body .="<br>". $mailBody;

        if(isset($edit))
        {
            $mail->AltBody = '';
        }
        else
        {
            $mail->AltBody = 'Hello Team,<br>I would like to request leave for the leave dates specified as follows.
        Application Date:' . $f3->get('issuedDate') . '<br>Leave requested from:' . $f3->get('leaveFrom') . '<br>Leave requested to:' . $f3->get('leaveTo') . '<br>Leave Description:' . $f3->get('leaveDescription') . 'Leave Type:' . $f3->get('leaveType').'<br><br>Hoping for a positive response.<br><br> Thank you.';
        }

        $mail->Subject = 'Updates on leave date applied';

        $mailStatus = (boolean)$mail->send();

        if ($mailStatus === true) {
            return $mail;
        }
    } catch (phpmailerException $e) {
        $response = array(
            'status'=>'error',
            'message'=>'Got some error while sending emails',
            'exceptions'=>$e->getMessage()
        );
        return $response;

    } catch (Exception $e) {
        $response = array(
            'status'=>'error',
            'message'=>'Got some error while sending emails',
            'exceptions'=>$e->getMessage()
        );

        return $response;
    }
}

我收到了一封垃圾邮件,虽然[只有一封]说:

This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing 

我无法弄清楚出了什么问题。

它一直工作到以前。我的收件箱里有很多电子邮件。

是否有发送电子邮件的限制?或者是否有人将其报告为垃圾邮件或欺骗?

很感谢任何形式的帮助。谢谢。

php phpmailer fat-free-framework
1个回答
1
投票

因为您正在使用SMTPSecure = 'ssl',所以您不会使用SMTPDebug = 2获得任何调试输出,因为它只显示SMTP级输出;您需要SMTPDebug = 3来显示连接级别的问题。这可能是由PHP配置中的过期CA证书引起的。有很多关于这个的报告,因为gmail最近更改了它们(为什么你的脚本停止工作)。它包含在the troubleshooting guide中。

另外,为什么要在计划文本AltBody中放置HTML标记?他们不会在那里工作。

© www.soinside.com 2019 - 2024. All rights reserved.