Jump to content

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 <reports@webstats.com>' . "\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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.