dongshuobei1037 2019-04-24 15:34
浏览 63

PHP中的Foreach循环重复其中每个元素的每个预期结果,我缺少什么? [重复]

This question already has an answer here:

I want to send each email a specific message, but the look is not working as expected, because the first email address receives her corresponding message, but the second email address receives two messages (the one for the first and the one for the second email in the list), and the third email receives three emails, each email with the message for each email.

This is my code:

$messages = array(
    'x1@gmail.com'=>'message for X1',
    'x2@gmail.com'=>'message for X2',
    'x3@gmail.com'=>'message for X3'
);

foreach ($messages as $key => $value) {
    $mail->addAddress($key);
    $mail->Subject = $value;
    $mail->send();
}

I tried unset($razones[$key]); before the loop ends, so the item is extracted from the array before continues, but still the output is not working.

This is what I get:

X1 receives 3 mails: message for X1 message for X2 message for X3

X2 receives 2 mails: message for X2 message for X3

X3 receives 1 mail: message for X3

The intended result I think is pretty obvious:

X1 receives 1 email: message for X1

X2 receives 1 email: message for X2

X3 receives 1 email: message for X3

I know that there is something silly not working in my logic, and staring right at my face, but I cannot see it after many hours of trying on my own.

I'll appreciate any help!

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划