Laravel 5.8无法实例化邮件功能

时间:2019-10-28 13:16:46

标签: smtp phpmailer laravel-5.8

我编写了一个每天发送电子邮件的功能。它在过去的4个月中一直正常工作。今天突然我得到了错误:

  

2019-10-28 13:00:01无法实例化邮件功能。

     

PHPMailer \ PHPMailer \ Exception:无法实例化邮件功能。

     

在G:\ intraets \ dynamicsbi \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php:1720

     

1716 | if(isset($ old_from)){
     1717 | ini_set('sendmail_from',$ old_from);
     1718 | }
     1719 |如果(!$ result){

     
    

1720 |抛出新异常($ this-> lang('instantiate'),self :: STOP_CRITICAL);

  
     

1721 | }
     1722 |
     1723 |返回true;
     1724 | }

发送电子邮件的代码是下一封:

$mail  = new PHPMailer\PHPMailer(true);

    try {
        // $mail->IsSMTP();  <-- yes, this is commented, I've never used this line and code worked.
        $mail->CharSet    = "utf-8";
        $mail->Host       = 'smtp.office365.com';
        $mail->SMTPAuth   = true;
        $mail->Username   = env('MAIL_USERNAME');
        $mail->Password   = env('MAIL_PASSWORD');
        $mail->Port       = 587;
        $mail->SMTPDebug  = 2;
        $mail->SMTPSecure = 'tls';

        $mail->IsHTML(true);
        $mail->Priority = 1;
        $mail->SetFrom("noreply@foo.bar",'Bar Baz');
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->AddAttachment('/output/temp/file.csv', 'filename.csv' );

        $emails = explode(',', $emails);

        foreach ($emails as $email) {
            $mail->AddAddress($email);
        }

        $mail->Send();

        Log::info('Email sent to ', array('email' => $emails));

    } catch (Exception $e) {
        Log::error($e);
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }

我修改了代码,但没有更改,我修改了环境变量MAIL_USERNAME和MAIL_PASSWORD,并且没有发现任何与以前不同的内容。一切似乎都是正确的,并且从今天开始,它一直运行良好。

我想念什么吗?

0 个答案:

没有答案