Jump to content

Mailing with While Loops


elmas156

Recommended Posts

I'm trying to send an email that has a list created from a while loop to multiple people with an email list created from while loop.  Can someone please help me figure this out?  My brain is fried.  Here's the code that I have:

 

This is producing an error message that reads: Parse error: syntax error, unexpected '{' in /home/content/29/6879529/html/calhoun/admin/sendreport.php on line 22

<?php
include("conf.inc.php");

$result = mysql_query("SELECT `prefix`,`lname`,`email` FROM admin");
$row = mysql_fetch_row($result);

$result2 = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC");
$row2 = mysql_fetch_row($result2);

$cdate = date('m-d-Y');

while ($row = mysql_fetch_row($result)) {

	$prefix = $row[0];
	$lname = $row[1];
	$adminemail = $row[2];
	$fullname = "$prefix $lname";

			$sendto = "$adminemail";
			$emailsubject = "Webstats Report For $cdate.";				

			while ($row2 = mysql_fetch_row($result2){ // This is line 22.

					$to = $row2[0];
					$from = $row[1];
					$subject = $row[2];
					$message = $row[3];
					$datetime = $row[4];

					$eachmessage = "<p>
					<hr width=\"400\">
					To: $to<br>
					From: $from<br>
					On $datetime<br> <br>
					$subject<br>$nbsp;<br>
					$message
					</p>";

			}

			$emailmessage = "<html>
			<body>
			$fullname,
			<p>
			Here is a list of the messages that have been exchanged in the last 24 hours.</p>
			$eachmessage
			</body>
			</html>";

			// To send HTML mail, the Content-type header must be set
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

			// Additional headers

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

			// Mail it
			mail($sendto, $emailsubject, $emailmessage, $headers);

}

?>

Link to comment
https://forums.phpfreaks.com/topic/217126-mailing-with-while-loops/
Share on other sites

OK, thanks for pointing that out.  Now I'm not getting the error message, but I'm not getting any emails sent either.  Is there a problem with the while loops that would cause a problem sending the emails?  I've never tried this before so I'm thinking there might be something wrong with the structure but I'm not sure.  Any suggestions?

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.