对于office365主机,Yii smtp邮件发送失败

时间:2017-08-08 06:50:26

标签: yii smtp

从YII发送邮件时,对于smtp协议,它会给出以下错误:

for /f "skip=14 delims=" %%a in ('dir /a-d /o-d /b /s "C:\Path_To_Folder"') do DEL "%%a"

即使端口更改为587,也会出现相同的错误。

Swift_TransportException: Expected response code 250 but got code "530", with message "530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BM1PR01CA0097.INDPRD01.PROD.OUTLOOK.COM] " in /var/www/html/vvf.kritva.in/protected/extensions/yii-mail/vendors/swiftMailer/classes/Swift/Transport/AbstractSmtpTransport.php:406 

控制器中的代码如下:

'transportType' => 'smtp', 
'transportOptions' => array( 
        'host'=>'smtp.office365.com', 
        'username'=>'xyz@xyz.com', 
        'password'=>'password', 
        'port'=>'587', 
     // 'encryption' => 'tls' 
 ),

请帮助纠正这个问题。

提前致谢。

3 个答案:

答案 0 :(得分:0)

所以主要问题是这一行:

$message->from = 'xyz@xyz.com';

您必须将此电子邮件地址更改为与office365.com中注册的电子邮件地址完全相同。如果您创建了名为monica@office365.com的电子邮件,则必须在发送前将其设为from()

答案 1 :(得分:0)

我也遇到了这个问题,我可以从一个帐户发送而不是另一个帐户,很多时候这是因为您尝试发送的帐户位于受保护的组中,例如管理员或打印机。

答案 2 :(得分:0)

\ config \ web.php

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'enableSwiftMailerLogging' => true,
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',               
            'plugins' => 
            [
                [
                    'class' => 'Swift_Plugins_LoggerPlugin',
                    'constructArgs' => [new Swift_Plugins_Loggers_ArrayLogger],
                ],
            ],
            'host' => 'smtp.office365.com',
            'authMode' => 'login',
            'username' => 'your email id',
            'password' => 'your password',
            'port' => '587',
            'encryption' => 'tls',
        ],
    ],

/////////////使用此功能发送邮件//////////////

public function sendemail($from,$to,$subject,$content)
 { 
    try{
        $mailCompose = Yii::$app->mailer->compose()
            ->setFrom($from)
            ->setTo($to);
        $mailCompose->setBcc($bccEmailIds);
        $mailCompose->setSubject($subject)
            ->setHtmlBody($content)
            ->send();
            $msg = 'Email sent';
    }catch(Exception  $e){
        $msg = $e->getMessage();
    }
}