我有一个 Symfony 项目(非常简化),如下所示:控制器/MyToolController.phpnamespace App\Controller;use App\Services\ToolsService;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;class MyToolController extends AbstractController{ private $toolsService; /** * @param ToolsService|null $toolsService */ public function __construct(ToolsService $toolsService = null) { $this->toolsService = $toolsService; } public function run() { // some more code here... $mailContent = $this->render('site/mail.html.twig', $data)->getContent(); $this->toolsService->sendMail($from, $to, $bcc, $mailContent, $subject); // if I remove the following line, no emails are sent out! return $this->render('site/thankyou.html.twig', $data); }}服务/MyToolService.phpnamespace App\Services;class ToolsService{ /** @var \Swift_Mailer */ private $mailer; /** * @param \Swift_Mailer $mailer */ public function __construct(\Swift_Mailer $mailer) { $this->mailer = $mailer; } public function sendMail($from, $to, $bcc, $body, $subject) { $mail = ( new \Swift_Message() ) ->setSubject($subject) ->setFrom($from) ->setTo($to) ->setBcc($bcc) ->addPart($body, 'text/html'); $res = $this->mailer->send($mail); $this->logger->info('Email sent'); return $res; }}如果您看一下,MyToolController.php您会看到我调用了发送电子邮件的服务。如果我在我的函数中返回一个Response对象run(),一切都会顺利 - 但如果我省略它,则不会发送任何内容。如果我在一个循环中发送多封电子邮件并且遇到超时也是如此。无论如何都会调用Strangely $mailer->send()- 它返回 1 - 我在sendmail()函数中写入的日志中看到一个条目。但是没有电子邮件离开服务器。这是我的 SwiftMailer 配置:swiftmailer: url: '%env(MAILER_URL)%' spool: { type: 'memory' }
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消