Short answer:
You're missing $template->setDecorator(true)
.
Long answer:
I extend sfMailer
and add a function called composeAndSendPartial that will send a partial to the provided email address. If you extend sfMailer
, make sure you update your factories.yml.
/**
* Composes and sends an email with a body from rending $partial with $parameters
* @param string $from From address
* @param string $to To address
* @param string $subject Email subject
* @param string $partial The partial to render. Can be in the form module/template, or simply template. If no module is provided,
* module "email" is assumed
* @param array $parameters An array of parameters to render the partial with
*/
public function composeAndSendPartial($from, $to, $subject, $partial, $parameters = array())
{
if (false !== $sep = strpos($partial, '/'))
{
$moduleName = substr($partial, 0, $sep);
$templateName = '_' . substr($partial, $sep + 1);
}
else
{
$moduleName = 'email';
$templateName = '_' . $partial;
}
$view = new sfPHPView($context, $moduleName, $templateName, '');
$view->getAttributeHolder()->add($parameters);
$view->setDecorator(true);
$view->setDecoratorTemplate('email.php');
$html = $view->render(); //the contents of the rendered template
$this->composeAndSendHtml($from, $to, $subject, $html); //properly sets email formats, attaches plain text version, etc.
}