duanhangjian8149 2011-11-30 18:16
浏览 18
已采纳

PHPMailer 5.1的模板变量

I'm using PHPMailer to send out an email based on a template file included this way:

$body = file_get_contents('petition_email.html');

The template contents a variable $name that I would like to replace with a value from my php script.

As of now, the script outputs $name as simple text along with the rest of the message.

How do I make sure that my template text is being parsed for variables and $name is being replaced with the actual value?

  • 写回答

1条回答 默认 最新

  • donglu5235 2011-11-30 18:25
    关注

    You could do

    $body = str_replace('$name', $name);
    

    Right after that file_get_contents call, if you are loading an HTML file. Make sure you assign your variable before you try to replace it though (assign it in the same script).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程