Email body in Symfony 1.4 mailer?

I use the Symfony 1.4 email program, where I create the various bits needed for email and then send them using:

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

In the body of the letter, I need to use the variables generated in the action, so right now I can do this in my action:

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

Does anyone know of an elegant way to store / organize various email bodies instead of writing them so directly to my action? I will have many email templates and will also have them in several languages.

I found an old Askeet tutorial that discusses this, but it seems a bit dated with the new SwiftMailer integration based on symfony 1.4, and the SwiftMailer documentation itself is not very clear.

Thank.

+3
source share
2 answers

I store the email bodies as a template file and pass them through sfPartialView. For instance. inside 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()

Body templates are located in the module template folder, but I'm sure you can somehow change this and, for example, put all the email templates in one folder if you want.

+5
source

How to use only native method available inside sfAction.

$ this-> getPartial ('partial_name'); which works as partial helpers for your templates.

+5
source

Source: https://habr.com/ru/post/1732605/


All Articles