I_G*_*I_G 2 email image insert swiftmailer symfony
我为客户开发了一个页面,我必须做一个时事通讯.我已经有了邮件的模板,我想要的是在这些电子邮件中插入图片.
代码 :
foreach($customer as $customer)
{
$mail = $customer->getMailcustomer();
$message = \Swift_Message::newInstance();
$message->setSubject('Info');
$message->setFrom('abcd@noreply.ch');
$message->setTo($mail);
$message->setContentType("text/html");
$message->setBody(
$this->renderView(
'MyBundle:Customer:email.html.twig',
array('form' => $form->createView())
)
);
$this->get('mailer')->send($message);
}
Run Code Online (Sandbox Code Playgroud)
此代码有效,我有一个很好的电子邮件页面,但我不知道如何在其中插入图片.
我试图插入一张图片,email.html.twig但它没有用.
以下是http://swiftmailer.org/docs/messages.html中的示例:
如果您愿意,可以分两个阶段嵌入文件.只需捕获变量中embed()的返回值,并将其用作src属性.
// You can embed files from a URL if allow_url_fopen is on in php.ini
$message->setBody(
'<html>' .
' <head></head>' .
' <body>' .
' Here is an image <img src="' .
$message->embed(Swift_Image::fromPath('http://site.tld/logo.png')) .
'" alt="Image" />' .
' Rest of message' .
' </body>' .
'</html>',
'text/html'
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5572 次 |
| 最近记录: |