Jump to content

Selecting all people from DB in php email


cdoggg94

Recommended Posts

I have a script where you add an entry into a DB. I want to take everyone from another table in this DB and send the newly added content to them.

My problem is displaying all of the contacts into the $to=   location.

This is what I currently have:

 

<?php

error_reporting(-1);
//-------------email section----------------//

$title = $_POST['title'];
$story = $_POST['story'];
$date = $_POST['date'];


//do { 
//$to = $row_Fake['fake_email'];
//} 
//while($row_Fake = mysql_fetch_assoc($Fake));


while ($row_Fake = mysql_fetch_assoc($Fake)) {  
	$to = $row_Fake['fake_email']; 
} 

//$to = "[email protected]";


$subject = "New Halnor Update!";

$message = "
<html>
<head>
<title>New Update!</title>


</head>
<body>

<div align='center'>";

//do{ echo $row_Fake['fake_email'].", "; } while($row_Fake = mysql_fetch_assoc($Fake));


//$row['fake_email'];

"We have a new update from ".$date." to share with you !<br /><br />
<table border='0'>
	
	<tr>
	<td valign='top' width='200'><b>".$title."</b></td>
	<td>".nl2br($story)."</td>
	</tr>	
	</table>
	
	
</div>
</body>
</html>
";

$x = 1;
$str = "test";
do{
   $str .= $x;
    $x++;
}while($x<10);

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>'. "\r\n";
//$headers .= 'Cc: [email protected]' . "\r\n";


mail($to,$subject,$message,$headers);


	
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>

Kind of lost right now. Can someone help?

 

Where are you defining $Fake? From what you've posted I don't see a query being executed.

 

I don't think you'd want to insert all the email addresses into 1 $to variable, you'll probably want to loop the process, otherwise you'll find all emails will be flagged as spam.

 

You also need to switch from mysql_* functions to mysqli_* .

to hide your user's email addresses from each other, you need to put them into a bcc: field. by putting them all into the to: field, the entire list will be visible to everyone who receives the email (and anyone can then hit reply-all to spam all your members.) when using a bcc: field, you would use your own from: email address as the to: address.

 

to make a list of email addresses, you would form a comma separated list. your current code only assigns one value over an over inside the while(){} loop, which would end up being the last value after the end of the while(){} loop.

$fake is defined like this:

 

<?php

mysql_select_db($database_HalNor, $HalNor);
$query_Fake = "SELECT* FROM fake_tbl";
$Fake = mysql_query($query_Fake, $HalNor) or die(mysql_error());
$row_Fake = mysql_fetch_assoc($Fake);
$totalRows_Fake = mysql_num_rows($Fake);

?>

Thank you both for the help

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.