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
        ...
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度