0

txtTo=email1,eamil2,email3;

foreach (array($_POST["txtTo"]) as $v) {
    $strTo = $v; 
    $flgSend = @mail($strTo,$strSubject,$strHeader1,$strHeader); 

    if($flgSend)  
    {  
    echo "$v Mail send completed.\n<br/>";  
    }  
    else  
    {  
    echo "$v Cannot send mail.\n<br/>";  
    } 
}

它向所有人发送电子邮件,所以我得到email1,eamil2,email3 Mail send completed.

除了

email1 Mail send completed.
eamil2 Mail send completed.
email3 Mail send completed.

怎么了?怎么给每个人发邮件而不是全部一起发?

4

2 回答 2

1

我的猜测是 $_POST["txtTo"] 已经是一个数组,尝试更改这一行:

foreach (array($_POST["txtTo"]) as $v) {

对此:

foreach ($_POST["txtTo"] as $v) {

如果 html 输入名称是 txtTo[],这意味着它是以数组的形式出现的。

列维

于 2013-02-03T15:10:02.010 回答
1

您需要在循环之前拆分单独的电子邮件地址;

$recipients = explode(',', $_POST['txtTo']);

foreach ($recipients as $v) {
    $strTo = $v; 
    $flgSend = @mail($strTo,$strSubject,$strHeader1,$strHeader); 

    if($flgSend)  
    {  
    echo "$v Mail send completed.\n<br/>";  
    }  
    else  
    {  
    echo "$v Cannot send mail.\n<br/>";  
    } 
}
于 2013-02-03T15:10:08.750 回答