使用php发送带有模板的电子邮件 [英] Send email with a template using php
本文介绍了使用php发送带有模板的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用php发送电子邮件,然后在电子邮件中添加模板设计?我使用这个:
How can I send an email using php then add a template design in the email? I'm using this:
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
它工作正常!问题是如何添加一个模板。
And it works fine! The problem is just how to add a template.
推荐答案
为什么不尝试像这样简单的东西:
Why not try something as simple as this :
$variables = array();
$variables['name'] = "Robert";
$variables['age'] = "30";
$template = file_get_contents("template.html");
foreach($variables as $key => $value)
{
$template = str_replace('{{ '.$key.' }}', $value, $template);
}
echo $template;
您的模板文件类似于:
<html>
<p>My name is {{ name }} and I am {{ age }} !</p>
</html>
这篇关于使用php发送带有模板的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文