2013-03-26 2 views
3

내가 Swiftmailer 심포니 2.1 및 된 이메일을 보낸 후 첨부 파일을 제거하려고 보내하지만 응답 객체 (리디렉션)을 반환하기 전에 파일을 삭제하면 이메일이 전송하지 않습니다 제거 .Swiftmailer는 부착 후

symfony가 응답에서 이메일을 보내기 때문에 이메일이 전송되면 첨부 파일이 이미 제거 되었기 때문에 이것이라고 생각합니다. 예를 들어

:

<?php 

// DefaultCotroller.php 

$message = \Swift_Message::newInstance($subject) 
    ->setFrom('[email protected]') 
    ->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')); 

의 옵션은 파일을 청소 크론 탭을 만드는 것입니다,하지만 난 그것을 사용하지 선호합니다.

감사합니다.

답변

7

현재 메모리 스풀을 처리하는 코드를 볼 수는 : https://github.com/symfony/SwiftmailerBundle/blob/master/EventListener/EmailSenderListener.php

이를 배치하는 데 사용됩니다 보내지는 이메일.

또한 다큐에 대한

 $transport = $this->container->get('mailer')->getTransport(); 

     $spool = $transport->getSpool(); 

     $spool->flushQueue($this->container->get('swiftmailer.transport.real')); 
+1

감사! 그 완벽하게 작동합니다 :) – Erioch

2

확실치 않지만 메시지 스풀로 인해이 문제가 발생할 수 있습니다. SF2 메모리 스풀은 기본적으로 사용됩니다. 즉, 메시지는 커널 종료 이벤트에서 전송됩니다.

파일을 삭제하기 전에 스풀을 플러시해야합니다. 이 문제의 원인 인 경우

잘 설명 솔루션을 이쪽을 봐 : http://sgoettschkes.blogspot.de/2012/09/symfony-21-commands-and-swiftmailer.html

+0

감사를 이메일을 보내는 동작을 모방하기 위해 send() 호출 후와 unlink() 호출하기 전에이 작업을 추가 할 수 있습니다! – Erioch