Php 在进程之前将字符串/var插入文件
我正在处理一个html电子邮件模板,一切正常。我只需要再做一件事,将用户名添加到电子邮件Php 在进程之前将字符串/var插入文件,php,Php,我正在处理一个html电子邮件模板,一切正常。我只需要再做一件事,将用户名添加到电子邮件$en['user']从文件加载html内容时是否可以这样做?或者,我必须将html电子邮件tpl代码内联到流程邮件文件中吗 ... $body = file_get_contents('emails/welcome.tpl'); mail($en['email'], $subject, $body, $headers); 编辑:这就是解决方案吗?参考下面的@Dagon评论 $tpl_body = file
$en['user']
从文件加载html内容时是否可以这样做?或者,我必须将html电子邮件tpl代码内联到流程邮件文件中吗
...
$body = file_get_contents('emails/welcome.tpl');
mail($en['email'], $subject, $body, $headers);
编辑:这就是解决方案吗?参考下面的@Dagon评论
$tpl_body = file_get_contents('emails/welcome.tpl');
$body = str_replace("%user%",$en['user'],$tpl_body);
mail($en['email'], $subject, $body, $headers);
使用@Dagon建议进行str\u replace我的解决方案如下
$tpl_body = file_get_contents('emails/welcome.tpl');
$body = str_replace("%user%",$en['user'],$tpl_body);
mail($en['email'], $subject, $body, $headers);
str_replace,preg_replace…@Dagon我对上面的代码做了更改,它会按照我发布的方式工作吗?
$tpl_body = file_get_contents('emails/welcome.tpl');
$body = str_replace("%user%",$en['user'],$tpl_body);
mail($en['email'], $subject, $body, $headers);