【发布时间】:2015-03-01 01:25:49
【问题描述】:
我目前没有收到使用以下配置的电子邮件,我想知道这是否与我的设置有关,可能缺少某些内容,或者它在 MAMP localhost 上不起作用?
公共配置目录下的main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
然后发送电子邮件(显示成功消息)
public function submitreview($email)
{
//return Yii::$app->mailer->compose(['html' => '@app/mail-templates/submitreview'])
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->title)
->setTextBody($this->description)
->attachContent($this->file)
->send();
}
【问题讨论】:
-
swiftMailer 应该在 localhost 上工作,但您需要指定您的 ISP 邮件服务器,并可能使用用户名和密码。我会参考stackoverflow.com/questions/4485635/… 或google.com.au/#q=swiftmailer+localhost
-
但是,如果您的意思是使用 localhost 作为邮件服务器,而不是在 localhost 上托管您的网站并通过 gmail 邮件服务器发送邮件。那么您将需要像水银邮件这样的东西来充当邮件服务器。
标签: php yii2 swiftmailer