Re: email newsletter with MySQL - help please!

From: Date: Mon, 13 Aug 2001 13:24:06 +0000
Subject: Re: email newsletter with MySQL - help please!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62418@lists.php.net to get a copy of this message
Try something like: <?php $listquery = "SELECT emailaddress FROM subscribers"; $listresult = mysql_query($listquery); $newsquery = "SELECT * FROM newsarticles"; $newsresult = mysql_query($newsquery); while($listrow = mysql_fetch_array($listresult)) { $newsrow = mysql_fetch_array($newsresult)) $message = $newsrow[article]; $recipient = $listrow[emailaddress]; $subject = "Welcome to my ezine"; $mailheaders = "From: Herman.Pijpers@infonomics.nl\n"; $mailheaders .= "Reply-To: herman.pijpers@infonomics.nl"; mail($recipient, $subject, $message, $mailheaders); } echo ("The message has been sent</p>"); ?> if it works, which it should, and you would like to know why, please email me and Ill explain it ;) > Being a rather new to php I find myself completely stuck on a script which > is possibly a piece of cake for most of you: > > I want to set up a weekly ezine. Both email addresses and news articles will > be retrieved from two separate MySQL tables called "subscribers" and > "newsarticles". > > I put together the following script but it doesn't work the way I want it > to: > > > <?php > > $listquery = "SELECT emailaddress FROM subscribers"; > $listresult = mysql_query($listquery); > while($listrow = mysql_fetch_array($listresult)) > { > $newsquery = "SELECT * FROM newsarticles"; > $newsresult = mysql_query($newsquery); > while($newsrow = mysql_fetch_array($newsresult)) > { > $message = $newsrow[article]; > } > > $recipient = $listrow[emailaddress]; > $subject = "Welcome to my ezine"; > $mailheaders = "From: Herman.Pijpers@infonomics.nl\n"; > $mailheaders .= "Reply-To: herman.pijpers@infonomics.nl"; > > mail($recipient, $subject, $message, $mailheaders); > } > > echo ("The message has been sent</p>"); > > > ?> > > That's it. A message IS being sent to all subscribers, but somehow, this > message only contains the latest newsarticle in the database in stead of the > whole array. What am I doing wrong? > > Any help in this will be greatly appreciated! > > Best, > Herman > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#62418) next »