2016-03-02 79 views
2

我有一個問題發送郵件,因爲symfony 2.8與SwiftMailer。 之前,我用這個方法:SwiftMailer setBody與數據庫

$body = $this->twig->render($email->getCorp()); 

隨着外部服務,但現在我有這個錯誤:

無法找到模板「<div> ......在數據庫模板...」

我已經試過這也和我有同樣的錯誤:

$email = $em->getRepository('BoAdminBundle:Email')->find(3); 
$body = $this->render($email->getCorp()); 
$message = Swift_Message::newInstance() 
        ->setSubject('Subject') 
        ->setFrom('[email protected]') 
        ->setTo($insti->getEmail()) 
        ->setContentType("text/html") 
        ->setBody($body); 
       $this->get('mailer')->send($message); 

感謝您的幫助:)!

編輯

$parametersFinal = array_merge($replaces, $replacesInsti); // $replacesInsti = array the client's informations 

    $body = $this->twig->render($email->getCorp(), $parametersFinal); 

我怎樣才能在體內插入這種 「$ parametersFinal」?

+0

'$ email-> getCorp()'返回什麼? –

+0

數據庫中包含html消息(電子郵件正文)的字段。 – pouletomorilles

+0

您的編輯似乎可能更好地作爲一個單獨的問題提供服務。 –

回答

1

根據您的意見,在HTML調用getCorp()功能,在這種情況下,你的代碼應該改爲存在:

$email = $em->getRepository('BoAdminBundle:Email')->find(3); 
$message = Swift_Message::newInstance() 
    ->setSubject('Subject') 
    ->setFrom('[email protected]') 
    ->setTo($insti->getEmail()) 
    ->setContentType("text/html") 
    ->setBody($email->getCorp()) 
; 
$this->get('mailer')->send($message); 

render()功能需要一個模板的名稱,以使作爲第一個參數,以及傳遞給該模板的可選參數數組。

+0

是的,它的工作原理! 非常感謝! 現在我將編輯帖子,因爲我需要在html正文中插入twig參數。 – pouletomorilles