2012-07-13 140 views
0

我有一个电子邮件数组,并希望为阵列中的每个条目发送一封电子邮件,但目前它只将它发送到第一个地址。我环顾四周,看不到我做错了什么。在foreach循环中调用require_once(),代码在每次迭代中都不可用

//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)<[email protected]>"; 
    //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"); 
} 

我使用PHP梨发送电子邮件,因为IT问题,但不应该重要,因为它要运行脚本,每次和发送电子邮件分开。

+0

你可以var_dump $ emails吗? – Gntem 2012-07-13 10:25:46

回答

2

的问题是这一行:

require_once ("sendemail.php"); 

...应该只是

require ("sendemail.php"); 

由于它是,它只会被包括在循环的第一次迭代,因此只有发送第一封电子邮件。

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

+0

更好的是仍然在循环之外移动你的require_once()语句,否则在循环中有一个require()语句,你会多次加载它。 – Brad 2012-07-13 10:34:44

+0

Durrrr非常感谢我这样一个数字,因为没有看到。我非常关注foreach和array,我认为这是错误所在。 – rmaspero 2012-07-13 10:35:06

+0

@rmaspero这些天你没有得到足够的“Durrrr”。我想念小学:-P – DaveRandom 2012-07-13 10:41:20

相关问题