Being a newbie 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($listrow = mysql_fetch_array($listresult))
{
$message = $newsrow[article];
}
$recipient = $listrow[emailaddress];
$subject = \"Welcome to my ezine\";
$mailheaders = \"From: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->\\n\";
$mailheaders .= \"Reply-To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->\";
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
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($listrow = mysql_fetch_array($listresult))
{
$message = $newsrow[article];
}
$recipient = $listrow[emailaddress];
$subject = \"Welcome to my ezine\";
$mailheaders = \"From: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->\\n\";
$mailheaders .= \"Reply-To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->\";
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