question regarding "mass mailer"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r34p3rex
Forum Newbie
Posts: 1
Joined: Mon Sep 25, 2006 5:50 pm

question regarding "mass mailer"

Post by r34p3rex »

I've been on and off with php for a few years and recently, i've made the jump back into web development so excuse my noobie code :)

heres the situation.. im helping my teacher create a site for some club of hers (big school club) and we have registrations with usernames/emails adn stuff like that. I'm kinda stuck with a mass mailer script right now (to send members announcements).

Here is the entire form processing file

Code: Select all

<?php require_once('Connections/database1.php'); ?>
<?php
mysql_select_db($database_database1, $database1);
$query_emails = "SELECT email FROM users";
$emails = mysql_query($query_emails, $database1) or die(mysql_error());
$totalRows_emails = mysql_num_rows($emails);

$source = $_GET['type'];
if(isset($source)) {
	if($source == email)
	{
		session_start();
		$headers = 'From: admin@iced-flame.net' . "\r\n" .
		 'Reply-To: admin@iced-flame.net' . "\r\n" .
		 'X-Mailer: PHP/' . phpversion();
	
		mail($_POST['emailto'], $_POST['subject'], $_POST['message'], $headers);
		
		echo("Mail sent");
		die();
	}
	
	if($source == massemail)
	{
	$headers = 'From: admin@iced-flame.net' . "\r\n" .
				 'Reply-To: admin@iced-flame.net' . "\r\n" .
				 'X-Mailer: PHP/' . phpversion();
		
		while ($row_emails = mysql_fetch_assoc($email)) {
		mail($row_emails['email'], $_POST['subject'], $_POST['message'], $headers);
		}
		
		echo("Mail sent to members");
		die();
	
	}
	else {
	echo ("Invalid source.");
	die();
	}
} else {
echo ("No source specified.");
die();
}
mysql_free_result($emails);
?>
What we're interested in is the part that starts with

Code: Select all

if($source == massemail)
We plan to have all the users stored in a table with a field for email. What i get from this script so far is that it doesn't cycle through the list of emails? is my syntax for the while loop wrong?
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

You have a spelling mistake on this line

Code: Select all

while ($row_emails = mysql_fetch_assoc($email)) {
Change the $email variable to $emails, which is the name of your result set.

$emails= mysql_query($query_emails, $database1) or die(mysql_error());
Post Reply