dongxian7471 2012-07-13 10:21 采纳率: 100%
浏览 218
已采纳

在foreach循环中调用require_once(),每次迭代都不能使用代码

I have an array of emails and want to send an email for each entry in the array but currently it only sends it to the first address. I have looked around and can't see what I am doing wrong.

//This is the array
$emails = array($teamleademail, $coleademail, $sponsoremail, $facilitatoremail, $cisupportemail);

//Now the foreach statment    
foreach ($emails as $value) {
    //pulls in email sending code
    require_once ("Mail.php");
    //variables required to send the email 
     $from = "Scope Sheet Process Database (no reply)<scopesheetprocess@goodrich.com>";
     //Make the $to variable that of the email in the array
     $to = "$value";
     $subject = "Scope Sheet $scopesheetid Closed";
     $body = "Scope Sheet $scopesheetid has been closed and can no longer be edited.";
     //send email code
     require_once ("sendemail.php");
}  

I am using pear php to send the email because of IT issues but that shouldn't matter since it should be running the scripts each time and sending separate emails.

  • 写回答

1条回答 默认 最新

  • drodsh7940 2012-07-13 10:26
    关注

    The problem is this line:

    require_once ("sendemail.php");
    

    ...should just be

    require ("sendemail.php");
    

    As it is, it will only be included on the first iteration of the loop, hence only the first email is sent.

    This on its own may not fix your problem - if it doesn't we'll need to see the code in sendemail.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路