douduanque5850 2011-09-05 14:38
浏览 114
已采纳

php str_replace用于带有邮件功能的循环中

I have an html email message assigned to a variable before it is used in a loop, then in the loop I try to use str_replace to insert custom values into hooks. So in the below example I have an {email} hook which I'm trying to replace with the recipient's email address. My problem is that when I output $message_final to the browser the str_replace function seems to have done the job. But when I send the email out, all the emails are still left with the {email} hook, and it appears that str_replace hasn't worked. Any ideas what i'm missing here? Thanks.

$message = "HTML email message here";

while ($r = mysql_fetch_array($emails_list)) {
    $email =  $r["email"];
    $message_final = "";

    if(!empty($email)) {
        //Replace hook with something new like an email address
        $message_final = str_replace('{email}', $email, $message);
        mail($email, $subject, $message_final, $headers); 
    }
}
  • 写回答

3条回答 默认 最新

  • doupa1883 2011-09-06 08:07
    关注

    Ahhhhh! Palm to face!! It was something completely different causing the issue. In my mail header I had the message attached there, and I was calling str_replace in the wrong bit of the code. Thanks for all your replies guys :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大