Hi,
I am putting together a newsletter to mail to a mailing list of less that 100 names. I would like to send an html email to all members listing the news headlines for this months issue. Before i send the newsletter i want to see all the headlies and then hit 'send' thus mailing out the newsletter to the names in my subscribers database. I've gotton as far as building a form with subject and message field but i am stuck on getting the headlines to send with the form, (they are not coming through when i recieve the mail.)
Also i want these headlines to link to the appropiate article on my website.
Below is the code i've been playing with but i would rather try another angle, if anyone has any suggestions.
Many Thanks
<?
//connect to database
$conn = mysql_connect( "host", "username", "p/word")
or die(mysql_error());
mysql_select_db("ab_db", $conn) or die(mysql_error());
//get email from the subscribers list
$sql = "select *
FROM newsletter";
$result = mysql_query($sql,$conn) or die(mysql_error());
//test to try and pull stuff out of database
while ($row =mysql_fetch_array($result)){
$headline = $row['headline'];
}
if ($_POST['op'] != "send" ){
//haven't seen the form , so show it
print "
<html>
<head>
<title>Mock Newsletter</title>
</head>
<body>
<h3>Send a Newsletter</h3>
<form method =\"POST\" action=\"$_SERVER[PHP_SELF]\" name=\"message\">
<p><strong>Subject</strong><br>
<input type=\"text\" name=\"subject\" size=30>
</p>
<p><strong><a href=\"http://localhost/unitech/docs/newsletter/mock_newsletter.php\">$headline</a></strong><br></p>
<p><strong>Content</strong><br>
<textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea>
</p>
<input type=\"hidden\" name=\"op\" value=\"send\">
<p><input type=\"submit\" name=\"send\" value=\"Send\"></p>
</form>
</body>
</html>";
}else if ($POST['op'] == "send"){
//want to send form so check for required fields
if (($POST['subject'] == "")|| ($_POST['message'] == "")){
header("Location: mailnews.php");
}
//connect to database
$conn = mysql_connect( "host", "username", "p/word")
or die(mysql_error());
mysql_select_db("unitech", $conn) or die(mysql_error());
//get email from the subscribers list
$sql = "select email
FROM newsletter_subscribers";
$result = mysql_query($sql,$conn) or die(mysql_error());
//create a From: mail header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "From: Your Mailing List\n";
//loop through results and send mail
while ($row = mysql_fetch_array($result)){
set_time_limit(0);
$email = $row['email'];
mail("$email", stripslashes($POST['subject']),
stripslashes($POST['message']), $headers);
print "Newsletter sent to: $email<br>";
}
}
?>