macattack Posted March 20, 2009 Share Posted March 20, 2009 Hi, I believe that the error here lies in the PHP and not in the MySQL. I have some code to look through a list of people (but only those with emails) and send an email to them. I tried to do an email this morning, (the mailing list has about 400 people and growing) and it would group names (ie. send "Hello Jane, Hello John, Hello Joe, ... etc. then send it to one person on the list, with the body of the message. Obviously, my intent is to hide names and emails of others on the list, so John would get the email that says "Hello John, --body--" If anyone knows why this is happening, it would be great to find out. I don't want to CC people as it's preferred that identities are secret for privacy reasons. <?php $subject = stripslashes(htmlentities($_POST['subject'])); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: [email protected]'; $body = stripslashes(nl2br(htmlentities($_POST['body']))); require("mysql.php"); $con = mysql_connect(PATH,USERNAME,PASSWORD); $db = mysql_select_db(DATABASE); if(!$db){ header("Location: index.php?database=false"); } else { $query = mysql_query("SELECT Name, Email FROM petitioners WHERE Email != '';"); while($row = mysql_fetch_assoc($query)) { $to = $row['Email']; $head = $_POST['head']." ".$row['Name'].","; $body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"><html><head><title>'.$subject.'</title></head><body><p>'.$head.'</p><p>'.$body.'</body></html>'; mail($to, $subject, $body, $headers); } header("Location: index.php?email=sent"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/ Share on other sites More sharing options...
jlhaslip Posted March 20, 2009 Share Posted March 20, 2009 And the question is??? Is this script working for you or not? Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789096 Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 That looks like it should work fine x.x. But anyway, you should probably use something besides mail() if you're doing a lot of emails at a time. mail() is notoriously slow. Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789100 Share on other sites More sharing options...
macattack Posted March 20, 2009 Author Share Posted March 20, 2009 No, it's not working. This morning I sent an email. It should have read: To John: "Hello John, --message---" To Jane: "Hello Jane, --message--" To Mary: "Hello Mary, --message--" Instead, every name was listed, with the subject in between each name. ie "Subject Hello John, Subject Hello Jane, Subject Hello Moe, etc. until end of list. --message--" It makes no sense (to me) Any help on why that happened would be great. Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789105 Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 That doesn't make sense..... Multiple messages were in one? That means that your variables being plugged in in the loop are wrong. No idea how else that could happen. Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789108 Share on other sites More sharing options...
macattack Posted March 20, 2009 Author Share Posted March 20, 2009 That's exactly what I thought. It looks right, but doesn't seem to work. It sounds like everyone received the email though. The first few were unaffected by the bug. Is there a simple way to move past the PHP mail function and implement something else? Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789117 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 mail function does not like post[''] Quote Link to comment https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789121 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.