Forum Moderators: coopster
if (is_array($_POST['f_name']) && is_array($_POST['f_name']) != "" )
{
foreach($_POST['f_name'] as $row=>$Act)
{
$f_name=$_POST['f_name'][$row];
$f_email=$_POST['f_email'][$row];
$Psubject = str_replace ('Recipient', $f_name, $Psubject );
$Pmessage = str_replace ('Recipient', $f_name, $Pmessage );
$headers = "From: $Yemail\r\nReply-To: $Yemail\r\n";
$headers .= "Content-type: text/html\r\n";
$message .= "$Pmessage";
$to = "$f_email" ;
$subject = $Psubject;
mail($to, $subject, $message, $headers);
}
echo '<pre>';
print_r($_POST['f_name']);
print_r($_POST['f_email']);
echo '</pre>';
If the array lengths don't match or you are getting repeated values in there somehow that may be the source of your errors.
Oh, and Welcome to WebmasterWorld! :)
$num = count($_POST['f_name']);
for($i = 0; $i < $num; $i++)
{
$f_name=$_POST['f_name'][$i];
$f_email=$_POST['f_email'][$i];
$Psubject = str_replace ('Recipient', $f_name, $Psubject );
$Pmessage = str_replace ('Recipient', $f_name, $Pmessage );
$headers = "From: $Yemail\r\nReply-To: $Yemail\r\n";
$headers .= "Content-type: text/html\r\n";
$message .= "$Pmessage";
$to = "$f_email" ;
$subject = $Psubject;
mail($to, $subject, $message, $headers);
}
$message .= "$Pmessage";
You're appending to $message with each iteration, so your email messages get longer and longer. Either set $message = '' at the top of your loop or change the statement to this:
$message = "$Pmessage"; // BTW, you don't really need the double-quotes here.
Hope this helps.
foreach($_POST['f_name'] as $row=>$Act)
{
// blah blah blah
mail($to, $subject, $message, $headers);
}
So, if i read this correclty, for each element in $_POST array, you send 1 email... no?
perhaps you need to construct your message inside your loop, but put the headers/mail part outside the loop
$Psubject = str_replace ('Recipient', $f_name, $Psubject );
$Pmessage = str_replace ('Recipient', $f_name, $Pmessage );
so once it picks up the name from the first loop it doesnt replace it after the second loop. I've tried unsetting both the $Psubject and $Pmessage after each loop but that doesnt work...any ideas?
foreach($_POST['f_name'] as $row=>$Act) {
$f_name = $_POST['f_name'][$row];
$f_email = $_POST['f_email'][$row];$to = "$f_email" ;
$subject = str_replace('Recipient', $f_name, $Psubject );
$message = str_replace('Recipient', $f_name, $Pmessage );$headers = "From: $Yemail\r\nReply-To: $Yemail\r\n";
$headers .= "Content-type: text/html\r\n";mail($to, $subject, $message, $headers);
}
with
$subject = str_replace('Recipient', $f_name, $Psubject );
$message = str_replace('Recipient', $f_name, $Psubject );
and removed the
$message .= "$Pmessage";
and that was it...script works perfectly....thanks alot guys