即时通讯在symfony4中发送电子邮件时遇到了麻烦。我正在关注documentation所以我使用composer req mailer
命令安装了swiftmailer。我的方法看起来像这样
public function sendAccountActivationLink(Array $data, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('myemail@gmail.com')
->setTo($data['email'])
->setBody(
$this->renderView(
'mails/registration.html.twig',
['data' => $data]
),
'text/html'
)
;
$mailer->send($message);
}
它说Swift_Mailer
类需要传输接口,但文档中没有任何内容。
我试图通过容器调用邮件程序
$this->get('mailer')->send($message);
但它说Call to a member function has() on null
另外,粘贴我的yml配置
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
transport: smtp
username: myemail@gmail.com
password: password
host: localhost
port: false
和邮件网址
MAILER_URL=gmail://myemail@gmail.com:password@localhost