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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵