小编Eri*_*och的帖子

Swiftmailer发送后删除附件

我发送电子邮件与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'));
Run Code Online (Sandbox Code Playgroud)

一个选项是创建一个crontab来清理文件,但我不想使用它.

谢谢!

php swiftmailer symfony

3
推荐指数
1
解决办法
3221
查看次数

标签 统计

php ×1

swiftmailer ×1

symfony ×1