Jump to content

Email error


macattack

Recommended Posts

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");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/150260-email-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789105
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/150260-email-error/#findComment-789117
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.