【发布时间】:2013-03-26 16:58:32
【问题描述】:
我在使用 Symfony 2.1 和 Swiftmailer 发送电子邮件后尝试删除附件文件,但如果我在返回响应对象(重定向)之前删除文件,电子邮件没有发送。
我想这是因为 symfony 在响应中发送了电子邮件,所以当电子邮件发送时,附件已经被删除了。
例如:
<?php
// DefaultCotroller.php
$message = \Swift_Message::newInstance($subject)
->setFrom('no-reply@dasi.es')
->setTo($emails_to)
->setBody($body, 'text/html')
->attach(\Swift_Attachment::fromPath('backup.rar'));
$this->get('mailer')->send();
unlink('backup.rar'); // This remove the file but doesn't send the email!
return $this->redirect($this->generateUrl('homepage'));
一个选项是创建一个 crontab 来清理文件,但我不喜欢使用它。
谢谢!
【问题讨论】:
标签: php symfony swiftmailer