我想从我的应用程序发送电子邮件,但我的主机需要额外的资金用于smtp协议
有没有办法通过swiftmailer
在yii2中使用pop3协议发送电子邮件?
答案 0 :(得分:2)
通过Yii2发送电子邮件您可以按照以下步骤操作。
<强> main.php 强>
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@app/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'email id',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
<强>控制器强>
\Yii::$app->mail->compose('your_view', ['params' => $params])
->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
->setTo('to_email@xyz.com')
->setSubject('This is a test mail ' )
->send();
有关详细信息,请参阅 Docs
答案 1 :(得分:-1)