来自模板中的phpmailer的回声变量

时间:2013-11-05 23:17:58

标签: php phpmailer

如何将变量从phpmailer传递给contents.php(模板文件)?我需要传递$email变量。

$mail -> msgHTML(file_get_contents('contents.php'), dirname(__FILE__));

contents.php

<div>
    This email was sent by x. <a href="www.x.com/process_contact.php?email="<?php echo $email ?> Unsubscribe </a>from this email.
</div> 

1 个答案:

答案 0 :(得分:1)

用您的电子邮件替换已知标签:

$email = 'your@email.com';
$mail -> msgHTML(str_replace('[emailhere]', $email, file_get_contents('contents.php')), dirname(__FILE__));

contents.php

<div>
    This email was sent by x. <a href="www.x.com/process_contact.php?email=[emailhere]"> Unsubscribe </a>from this email.
</div> 

手动:http://php.net/manual/en/function.str-replace.php