2011-12-19 27 views
0

我正在處理html電子郵件模板,一切正常。我只需要做更多的事情,將用戶名添加到電子郵件$en['user'];這是可能的,當從一個文件加載HTML內容?或者,我是否必須將html電子郵件tpl代碼內嵌到流程郵件文件中?在處理之前將字符串/ var插入文件

... 
$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); 
+1

str_replace函數,preg_replace函數... – 2011-12-19 19:15:21

+0

@Dagon我做了一個改變我上面的代碼,它會按我發佈的方式工作? – acctman 2011-12-19 23:19:29

回答

-1
ob_start(); 
include 'foo.tpl'; 
$body = ob_get_clean(); 
0

使用@Dagon建議爲str_replace我的解決方案是低於....

$tpl_body = file_get_contents('emails/welcome.tpl'); 
$body = str_replace("%user%",$en['user'],$tpl_body); 

mail($en['email'], $subject, $body, $headers); 
相關問題