dongtaotao19830418 2015-08-17 08:08
浏览 90
已采纳

使用$ mail php发送不同的电子邮件内容

I have a small problem here that I'm tried to fix for some couple of hours already. I have a PHP $mail function that send emails to multiple addresses using PHP for loop, like:

foreach($recipients as $name => $email){
    $mail->AddAddress($email, $name);
};

Problem is:

I need to get inside the Body message, each email from each user at the time of sending the message, so I can use it as variable inside the body message, I've already tried to use another foreach inside, but no luck.

So the PHP will be something like this:

$mail->Body .='Start of the message';
$mail->Body .='path_url?user_email='.$recipient.'';
$mail->Body .='Endof the message';

Is this possible using $mail?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongwo1914 2015-08-17 19:00
    关注

    You should use the same for loop for both email addresses and your content.

    With out knowing your code in details, I assume you have array contenting recipients email, name and message or something else.

    Some thing like this with out testing it:

    foreach ($recipients as $value)
    {
        $mail->AddAddress($value['email'], $value['name']);
        $mail->Body .= 'Start of the message';
        $mail->Body .= 'path_url?user_email=' . $value['recipient'];
        $mail->Body .= 'Endof the message';
        ...
        the rest of your $mail code if there so
        ...
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求组态王串口自定义通信配置方法或代码?
  • ¥15 实验 :UML2.0 结构建模
  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验
  • ¥15 为什么shp文件会有这种小方块?
  • ¥15 ecplise在连接数据库时显示加载驱动成功但是数据库连接失败
  • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 Multisim红外倒车雷达仿真中距离问题
  • ¥15 请上面代码做什么处理或什么混淆