Symfony 1.4邮件中的电子邮件正文?

Tom*_*Tom 3 email symfony1 swiftmailer

我正在使用Symfony 1.4邮件程序,我在其中构建了电子邮件所需的各种位,然后使用以下命令将其发送出去:

$this->getMailer()->composeAndSend($sender, $recipient, $subject, $body);
Run Code Online (Sandbox Code Playgroud)

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

$body = 'Your username is '.$username.' and this is the email body.';
Run Code Online (Sandbox Code Playgroud)

有没有人知道存储/组织各种电子邮件正文的优雅方式,而不是像这样直接编码我的行为?我将有许多电子邮件模板,并且还将使用多种语言.

我发现了一个旧的Askeet教程讨论这个,但它似乎有点过时与SwiftMailer的新symfony 1.4集成,而SwiftMailer文档本身对此并不十分清楚.

谢谢.

Fel*_*ing 5

我将电子邮件正文存储为模板文件并通过它们进行渲染sfPartialView.例如,在一个动作中:

$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()
Run Code Online (Sandbox Code Playgroud)

正文模板位于模块的模板文件夹中,但我相信您可以以某种方式更改此内容,例如,如果您愿意,可以将所有电子邮件模板放入一个文件夹中.


Hen*_*kov 5

如何在sfAction中使用本机方法.

$这 - > getPartial( 'partial_name'); 它的作用类似于模板的部分助手.