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.
有什么问题?如何将邮件发送给每个人而不是所有人?
答案 0 :(得分:1)
我的猜测是$ _POST [“txtTo”]已经是一个数组,请尝试更改此行:
foreach (array($_POST["txtTo"]) as $v) {
到此:
foreach($ _POST [“txtTo”]为$ v){
如果html输入名称为txtTo [],则意味着它以数组形式出现。
列维
答案 1 :(得分: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/>";
}
}