Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

How about just using the native method availible inside sfAction.

$this->getPartial('partial_name'); which works like the partial helpers for you templates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top