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


Calling require_once() inside foreach loop, code is not available on each iteration

我有一个电子邮件数组,想为数组中的每个条目发送一封电子邮件,但目前它只将其发送到第一个地址。我环顾四周,看不出我做错了什么。

//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");
}  

由于IT问题,我使用pear-php发送电子邮件,但这并不重要,因为它每次都应该运行脚本并发送单独的电子邮件。

问题是这一行:

require_once ("sendemail.php");

应该只是

require ("sendemail.php");

事实上,它只会包含在循环的第一次迭代中,因此只发送第一封电子邮件。

这本身可能无法解决您的问题——如果不能,我们需要在sendemail.php中查看代码。