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 をメーラー ライブラリとして使用し、それらの {strings} を mailFooter() 関数内で置き換える方法。

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 に答える