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();

我使用 PHPMailer 作为 Mailer 库以及如何替换 mailFooter() 函数中的那些 {strings}。

4

2 回答 2

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);
于 2012-11-28T13:28:58.230 回答
-1
    private arr = array(
    "{title}" => "Home page",
    "{email}" => "my@mail.com",
    ...
    );
    private $content = "Title for my site - {title}, if you interesting my email addres -> {email}"

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

echo $this->content;

此返回 -> “我的网站的标题 - 主页,如果您对我的电子邮件地址感兴趣 -> my@mail.com”

于 2013-03-22T14:26:33.603 回答