使用PHP中的SwiftMailer和预先构建的电子邮件模板更改值
I have used SwiftMailer a number of times for basic email sending, however I am trying to get the grips on sending more streamlined emails - so as to allow quicker creation of emails using templates.
I know I can manually create a template using the Decorator Plugin but this still feels very manual?
When I am building my PHP code I generally use TWIG templates, is there a way this can be integrated into SwiftMailer so I can send a predefined template using variables defined at the time of sending?
我已经多次使用SwiftMailer进行基本的电子邮件发送,但是我试图抓住发送更多信息 简化的电子邮件 - 以便使用模板更快地创建电子邮件。 p>
我知道我可以使用装饰器插件 strong>手动创建模板但这仍然感觉非常手动 ? p>
当我构建我的PHP代码时,我通常使用TWIG模板,有没有一种方法可以将它集成到SwiftMailer中,这样我就可以使用发送时定义的变量发送预定义的模板 ? p>
div>
Ok so I managed to find a way to do this, for anyone who may be looking at trying this, the following code is a good example :
$message_content = $app->render('email.template.twig',
array('name'=>'JustSteveKing', 'age'=>26));
$transport = Swift_SmtpTransport::newInstance("$host", $port)
->setUsername("$email")
->setPassword("$password");
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance("$title")
->setFrom(array("$sender_email" => "$sender_name"))
->setTo(array("$reciever_email"))
->setBody($message_content,'text/html');
$result = $mailer->send($message);