maplins Posted May 11, 2010 Share Posted May 11, 2010 The form sends email to all users without problems but duplicates the "From" header - if you're 4th in the database, you get the header 4 times, 5th gets it 5 times etc. Here is the code from the handling script. Can anyone suggest how to stop this happening? //set variables from form $form_subject=$_POST['subject']; $content=$_POST['content']; // pull data from the database $results=mysql_query("select * from mailing_list"); while($row=mysql_fetch_array($results)) { //send email $mailto=$row['email']; $subject="$form_subject"; $headers.="From: xxxx <xxxx@xxxx>\r\n"; $headers.="Reply-To: xxxx@xxxx\r\n"; $headers.="MIME-Version: 1.0\r\n"; $headers.="Content-type: text/plain; charset=iso-8859-1\r\n"; $message="$content" ; mail($mailto, $subject, $message, $headers) or die("Error sending email"); } Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/ Share on other sites More sharing options...
Muddy_Funster Posted May 11, 2010 Share Posted May 11, 2010 dont select * Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056384 Share on other sites More sharing options...
maplins Posted May 11, 2010 Author Share Posted May 11, 2010 Thanks for the quick reply! I'm still a novice at this - what difference will that make? Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056385 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 you could just set it up to BCC everyone all at once instead of bogging down the server with hundreds of e-mail requests. http://php.net/manual/en/function.mail.php Example #4 would work well, you would only have to modify the BCC header to place everyone's e-mail in a line separated via a comma. $headers .= 'Bcc: <[email protected]>, <[email protected]>, <[email protected]>' . "\r\n"; this way your server gets 1 e-mail request. Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056399 Share on other sites More sharing options...
bulrush Posted May 11, 2010 Share Posted May 11, 2010 Init your $headers variable each time like this: $headers=""; $headers.="From: xxxx <xxxx@xxxx>\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056429 Share on other sites More sharing options...
kenrbnsn Posted May 11, 2010 Share Posted May 11, 2010 Pull the addresses from the database, saving them in a temporary array, then create/send the email: <?php //set variables from form $subject=$_POST['subject']; $message=$_POST['content']; $bcc = array(); // pull data from the database $results=mysql_query("select email from mailing_list"); while($row=mysql_fetch_array($results)) { $bcc[] = $row['email']; } $headers = array(); $headers[] = "From: xxxx <xxxx@xxxx>"; $headers[] = "Reply-To: xxxx@xxxx"; $headers[] = "Bcc: " . implode(', ',$bcc); //put the collected email addresses in the BCC line $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; mail('[email protected]', $subject, $message, implode("\r\n",$headers)) or die("Error sending email"); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056439 Share on other sites More sharing options...
Kryptix Posted May 11, 2010 Share Posted May 11, 2010 Why BCC? Can you really have unlimited BCC's and send it like that? Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056456 Share on other sites More sharing options...
kenrbnsn Posted May 11, 2010 Share Posted May 11, 2010 Using a Bcc doesn't expose all the email addresses to everyone else. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056485 Share on other sites More sharing options...
Kryptix Posted May 11, 2010 Share Posted May 11, 2010 Using a Bcc doesn't expose all the email addresses to everyone else. Ken But why not send an e-mail per e-mail address? Is that bad? Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056832 Share on other sites More sharing options...
kenrbnsn Posted May 12, 2010 Share Posted May 12, 2010 One email per address puts a large strain on the email system if you're sending many email messages. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201354-sending-email-from-web-form/#findComment-1056884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.