简体   繁体   English

发送邮件yii2 zoho

[英]send mail yii2 zoho

Im using swiftmailer in yii2 and zoho to send mail. 我在yii2和zoho中使用swiftmailer发送邮件。 Here is my config: 这是我的配置:

'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',
            ],
        ],

and here is my function: 这是我的功能:

public function SendMail($from, $to,$subject, $body)
    {
        Yii::$app->mailer->compose()
            ->setFrom($from)
            ->setTo($to)
            ->setSubject($subject)
            ->setTextBody($body)
            ->send();
    }

It didn't work on server(integrate ssl) but it work find on my local, I've tried to debug but it return null and no exception. 它在服务器(集成ssl)上不起作用,但是在我的本地服务器上可以找到,我尝试调试,但它返回null且没有异常。 Can anyone have any idea to slove this stuff. 任何人都可以有任何想法来解决这个问题。 Thanks in advance. 提前致谢。

You have to use yii getLastTransaction() function to check last transaction 您必须使用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);

}

you can check also there :- Swiftmailer in Yii2 - Unable to send email 您也可以在此处检查: -Yii2中的Swiftmailer-无法发送电子邮件

Check your production server firewall. 检查生产服务器防火墙。 I have seen some shared hosting environments blocking smtp ports eg 587 我看到一些共享托管环境阻止了smtp端口,例如587

to check if your 587 outgoing port is open type into console 检查您的587传出端口是否打开,进入控制台

telnet smtp.zoho.com 587

if you get a successful response eg: 如果您获得成功的响应,例如:

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

Then your firewall is ok and the problem must be somewhere else. 然后您的防火墙就可以了,问题可能出在其他地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM