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 using PHPMailer as Mailer library and how to replace those {strings} inside the mailFooter() function.

4
  • Doesn't make sense; check this codepad Commented Nov 28, 2012 at 13:17
  • mailerFooter($content); function is called mailFooter() Commented Nov 28, 2012 at 13:17
  • @Bondye I hope that's just a typo. Commented Nov 28, 2012 at 13:18
  • So you are writing your own templating engine? You should try twig: twig.sensiolabs.org Commented Nov 28, 2012 at 13:35

2 Answers 2

4

use array

$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);
Sign up to request clarification or add additional context in comments.

Comments

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

This return -> "Title for my site - Home page, if you interesting my email addres -> [email protected]"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.