Yii2 Swiftmailer有时无法连接到SMTP,返回内部服务器错误

有时我的程序可以发送消息,有时候不是,据我的一位同事说,这是因为这里的连接 在我们的地方。 有时我无法ping通SMTP地址。</ p>

现在我尝试重试在循环中发送消息,但它没有,因为程序将因内部服务器错误而停止。 </ p>

  $ mail_params = $ params ['mail']; 
$ transport = \ Swift_SmtpTransport :: newInstance($ mail_params ['smtp'],$ mail_params ['port' ],$ mail_params ['encryption'])
  • &gt; setUsername($ mail_params ['user'])
  • &gt; setPassword($ mail_params ['password']);

    $ mailer = \ Swift_Mailer :: newInstance($ transport);
    $ message = \ Swift_Message :: newInstance($ subject)

  • &gt; setFrom([Yii :: $ app-&gt; params ['notificationEmail'] =&gt;'TMC Scheduler '])

  • &gt; setTo([$ to])

  • &gt; setBody(trim($ email_message));

    while($ i = 0){
    $ i = $ mailer-&gt ;发送($ message);
    }

返回$ i
</ code> </ pre>

我已经被困在这里4天了。 你们有什么想法吗? 我已经没用了。</ p>
</ div>

展开原文

原文

Sometimes my program can send a message and sometimes not, according to one of my colleagues it is because of the connectivity here in our place. Sometimes I can't ping the SMTP address.

Now I tried retrying to send the message in a loop, yet it doesn't because the program will stop because of an internal server error.

  $mail_params = $params['mail'];
  $transport = \Swift_SmtpTransport::newInstance($mail_params['smtp'], $mail_params['port'], $mail_params['encryption'])
  ->setUsername($mail_params['user'])
  ->setPassword($mail_params['password']);

  $mailer = \Swift_Mailer::newInstance($transport);
  $message = \Swift_Message::newInstance($subject)
               ->setFrom([Yii::$app->params['notificationEmail'] => 'TMC Scheduler'])
               ->setTo([$to])
               ->setBody(trim($email_message));

             while ($i = 0) {
                $i = $mailer->send($message);
             }

             return $i

I've been stuck here 4 days. Do you guys have any ideas? I'm running out of it.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐