电子邮件身体在Symfony 1.4邮件? [英] Email body in Symfony 1.4 mailer?

查看:121
本文介绍了电子邮件身体在Symfony 1.4邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Symfony 1.4邮件程序,在那里我构建了电子邮件所需的各种位,然后使用以下方式发送出去:

  $ this-> getMailer() - > composeAndSend($ sender,$ recipient,$ subject,$ body); 

在电子邮件正文中,我需要能够利用动作中生成的变量,所以正确现在我可以在我的行动中得到这个:

  $ body ='你的用户名是'$ username'电子邮件正文有没有人知道存储/组织各种电子邮件正文的优雅方式,而不是编码它们像这样直接进入我的行动?我会有很多电子邮件模板,并且还会使用多种语言。



我发现一个旧的Askeet教程讨论了这一点,但是似乎有点过时了symfony 1.4集成了SwiftMailer,而SwiftMailer文档本身并不是很清楚。



谢谢。

解决方案

我将电子邮件正文存储为模板文件,并通过 sfPartialView 。例如。在一个动作内:

  $ view = new sfPartialView($ this-> getContext(),$ this-> getModuleName ),$ this-> getActionName(),'confirmation_mail'); 
$ view-> setTemplate('_ confirmation_mail.php');

//可以设置值。通过setAttibute
$ view-> setAttribute('name',$ name);

$ body = $ view-> render()

模板位于模块的模板文件夹中,但我相信您可以以某种方式更改此模式,例如如果你想要,将所有的电子邮件模板放入一个文件夹。


I'm using the Symfony 1.4 mailer where I build the various bits needed for an email and then send it out using:

$this->getMailer()->composeAndSend($sender, $recipient, $subject, $body);

In the email body, I need to able to take advantage of variables generated in the action, so right now I might have this in my action:

$body = 'Your username is '.$username.' and this is the email body.';

Does anyone know of an elegant way of storing/organising various email bodies, instead of having to code them like this straight into my action? I will have many email templates and will also have them in multiple languages.

I've found an old Askeet tutorial discussing this but it seems somewhat out of date with the new symfony 1.4 integration of SwiftMailer, and SwiftMailer documentation itself isn't very clear on this.

Thank you.

解决方案

I store the email bodies as a template file and render them via sfPartialView. E.g. inside an action:

$view = new sfPartialView($this->getContext(), $this->getModuleName(), $this->getActionName(), 'confirmation_mail');
$view->setTemplate('_confirmation_mail.php');

// values can be set e.g. by setAttibute
$view->setAttribute('name', $name);

$body = $view->render()

The body templates are located in the module's template folder, but I am sure you can somehow change this and e.g. put all email templates into one folder if you want to.

这篇关于电子邮件身体在Symfony 1.4邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆