2011-12-19 1 views
0

저는 HTML 전자 메일 템플릿을 처리하고 있습니다. 모든 것이 잘 작동합니다. 한가지 더 할 일이 필요합니다. 사용자 이름을 이메일에 추가해야합니다. $en['user']; 파일에서 HTML 콘텐츠를로드 할 때 이것이 가능합니까? 아니면 html 이메일 tpl 코드를 프로세스 메일 파일에 인라인해야합니까?문자열/var를 프로세스 전에 파일에 삽입합니다.

... 
$body = file_get_contents('emails/welcome.tpl'); 
mail($en['email'], $subject, $body, $headers); 

수정 : 이것이 해결책일까요? 아래 @Dagon comment와 관련하여? 내 솔루션은 다음과 같습니다 str_replace에 대한 @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이다 ... –

+0

@Dagon가 나는 것, 위의 내 코드로 변경 한 제가 게시 한 방식대로 작동합니까? – acctman

답변

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

....

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

mail($en['email'], $subject, $body, $headers); 
관련 문제