我在yii2和zoho中使用swiftmailer发送邮件。这是我的配置:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a uploads by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.zoho.com',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'TLS',
],
],
这是我的功能:
public function SendMail($from, $to,$subject, $body)
{
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setTextBody($body)
->send();
}
它不能在服务器上运行(集成ssl),但是可以在我的本地服务器上找到,我尝试调试,但是它返回null也不例外。任何人都可以有任何想法来解决这个问题。预先感谢。
答案 0 :(得分:0)
您必须使用yii getLastTransaction()
函数来检查上一笔交易
public function SendMail($from, $to,$subject, $body)
{
Yii::$app->mailer->compose()
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setTextBody($body)
->send();
$status = Yii::$app->mailer->getLastTransaction();
echo "<pre>";
print_r($status);
}
您也可以在此处查看:-Swiftmailer in Yii2 - Unable to send email
答案 1 :(得分:0)
检查生产服务器防火墙。我看到一些共享的托管环境阻止了smtp端口,例如587
检查您的587传出端口是否为开放式,进入控制台
telnet smtp.zoho.com 587
如果您获得成功的答复,例如:
Trying 65.154.166.201...
Connected to smtp.zoho.com.
Escape character is '^]'.
220 mx.zohomail.com SMTP Server ready July 9, 2018 11:58:54 PM PDT
那您的防火墙还可以,并且问题必须出在其他地方。