php - 在 Symfony 4 中使用 swift mailer 发送邮件
问题描述
我正在尝试使用 symfony 4 通过 swift mail 发送电子邮件。下面的代码是我迄今为止尝试过的。但是电子邮件没有发送。
.env
MAILER_URL=smtp://localhost:25?encryption=&auth_mode=
控制器
/**
* @Route("/registration", name="new_registration")
* Method({"GET","POST"})
*/
public function newRegistration(Request $request, \Swift_Mailer $mailer)
{
if ($form->isSubmitted() && $form->isValid()){
$message = (new \Swift_Message('Hello Mail'))
->setFrom('noreply@cccc.org')
->setTo('abcccc@gmail.com')
->setBody(
$this->renderView(
'main/registrationEmail.html.twig',
['name' => $name]
),
'text/html'
);
try {
$mailer->send($message);
} catch (\Swift_TransportException $exception) {
echo $exception->getMessage();
} catch (\Exception $exception) {
echo $exception->getMessage();
}
return $this->render('main/registrationSuccess.html.twig');
}
return $this->render('main/registration.html.twig');
}
没有显示任何错误。但是邮件没有发送。请帮助我。
更新
我尝试通过控制台发送并使用php bin/console swiftmailer:email:send
. 从那我得到以下错误。
2019-03-14T11:40:32+01:00 [error] Exception occurred while flushing email queue: Connection could not be established with host localhost [No connection could be made because the target machine actively refused it.
#10061]
解决方案
推荐阅读
- reactjs - Reactjs、GraphQL 和 Redux - 如何自动处理博客的分页?
- centos7 - CentOS7 ccollab 与 perforce CL 更新问题
- smtp - Adaptive Server Enterprise 数据库中的 UTL_SMTP 实用程序
- angular - 在 Angular 6 应用程序中托管 React 组件
- docker - Docker:通过 CLI 使用 --password 是不安全的。使用 --password-stdin
- tensorflow - 6 阶多项式回归无结果
- android - 错误:x86 仿真当前需要硬件加速!(安卓工作室)
- c++ - 使用 try/catch 处理字符串流错误
- apache-spark - 在 Spark 中并行读取多个 CSV 会减慢速度
- git - ubuntu 上的 git difftool 仅在终端上返回差异,而不是使用 meld