I have a form field on my page where people can send a link to a friend, etc. I want to be able to allow them to enter more thatn 1 email address seerated by a "," and also validate the email addres before sent.
In my form, I have the text field named as "email_addr[]"
on my validate routine, I have the following:
foreach ($email_addr as $em) {
if (!strlen(trim($em))) {
$err_email="Please enter an email address";
$err_cnt++;
} else {
if (!validate_email($em)) {
$err_email = "Please enter a valid email address";
$err_cnt++;
}
}
}
and in my mail script, I have the following:
$arr_num = count($email_addr);
for ($i=0; $i<=$arr_num; $i++) {
$recipient=$email_addr[$i];
$subject=$subject;
$body="Directions have been sent to you.<br><br>"
.$comments . "<br><br>"
."To view your directions, click on this link or cut and paste this link into your browser's location bar:<br>"
."<a href=" . $url . ">" . $url_abbr . "</a><br><br>"
.$footer;
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From:" . $from . "\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($recipient, $subject, $body, $headers);
}
My problem is that if you only put 1 email address in, it works fine and I get my email. If you put in more thatn 1, seperated by the ",", it fails the validation.
Any suggestions?
Thanks!!