我有一個 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 關注
- 86 瀏覽
添加回答
舉報
0/150
提交
取消