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.
<br/>";
}
else
{
echo "$v Cannot send mail.
<br/>";
}
}
It send email to all so I get email1,eamil2,email3 Mail send completed.
except of
email1 Mail send completed.
eamil2 Mail send completed.
email3 Mail send completed.
What is wrong? how to send mail to each person not to all together?
You need to split the separate e-mail addresses before looping;
$recipients = explode(',', $_POST['txtTo']);
foreach ($recipients as $v) {
$strTo = $v;
$flgSend = @mail($strTo,$strSubject,$strHeader1,$strHeader);
if($flgSend)
{
echo "$v Mail send completed.
<br/>";
}
else
{
echo "$v Cannot send mail.
<br/>";
}
}
My guess is that $_POST["txtTo"] is already an array, try changing this line:
foreach (array($_POST["txtTo"]) as $v) {
to this:
foreach ($_POST["txtTo"] as $v) {
If the html input name is txtTo[] that means it is coming in as an array.
Levi