2012-11-28 42 views
0
**User_Tpl.html** 
<html><head></head> 
<body> 
Hello {NAME}, 
Business name : {BUSINESS_NAME}. 
Tel : {TELEPHONE}. 
Mob : {MOBILE}. 
</body> 
</html> 
function mailFooter($content) { 

    $sBusiness = 'Business name'; 
    $sTelp = '0'; 
    $sMobile = '0'; 

    $content = str_replace('{BUSINESS_NAME}', $sBusiness, $content); 
    $content = str_replace('{TELEPHONE}', $sTelp, $content); 
    $content = str_replace('{MOBILE}', $sMobile, $content); 

    return $content; 
} 

$content = file_get_contents('page/email/User_Tpl.html'); 
$content = str_replace('{SUBJECT}', $subject, $content); 
$content = str_replace('{NAME}', $ownerName, $content); 

**mailerFooter($content);** 
// always return {BUSINESS_NAME}, {TELEPHONE} 

$mail->AddAddress($email); 
$mail->SetFrom($name); 
$mail->AddReplyTo($reply); 
$mail->Subject = trim($subject); 
$mail->MsgHTML(trim($content)); 
$mail->IsHTML(true); 
$mail->Send(); 

IM。PHP的file_get_contents然後使用PHPMailer的作爲郵件程序庫以及如何更換那些{字符串}的mailFooter()函數中的函數替換字符串

+0

不使感;檢查[這個鍵盤](http://codepad.viper-7.com/qmICKH) –

+0

'mailerFooter($ content);'函數被稱爲'mailFooter()' –

+0

@Bondye我希望這只是一個錯字。 –

回答

4

使用數組

$content =' 
<html><head></head> 
<body> 
Hello {NAME}, 
Business name : {BUSINESS_NAME}. 
Tel : {TELEPHONE}. 
Mob : {MOBILE}. 
</body> 
</html>'; 

$search= array ('{BUSINESS_NAME}','{TELEPHONE}','{MOBILE}'); 
$replace=array($sBusiness,$sTelp,$sMobile); 
$content =str_replace($search,$replace,$content); 
-1
private arr = array(
    "{title}" => "Home page", 
    "{email}" => "[email protected]", 
    ... 
    ); 
    private $content = "Title for my site - {title}, if you interesting my email addres -> {email}" 

$this->content = strtr($this->content, $this->arr); 

echo $this->content; 

這回 - > 「標題爲我的網站 - 主頁,如果你有意思我的電子郵件ADDRES - > [email protected]

相關問題