by Amrit Hallan
Posted on March 29, 2004
|
|
Editors Note: This is a continuation of a previous article. You can find this article here.
The time has arrived to launch your publishing career at last. The subscribers have subscribed and your emails have been validated. Now all you have to do is, write the newsletter, copy/pase it in the box and click the submit button
We can publish text newsletter as well as HTML newsletter. We'll see how.
First the form:
The form has three fields, namely, Subject, Body and a checkbox to decide whether you want to send a plain newsletter or an HTML newsletter. This form uses the file "send_newsletter.php" to send the newsletter. Here's send_newsletter.php:
Most of the initial code must be clear by now. If not, please refer to the links mentioned at the beginning of the article. We use the function stripslashes() to take care of all the characters that PHP finds unpalatable (such as double-quotes and single-quotes). The if condition checks whether you have selected the HTML checkbox. If yes, then the necessary encoding is added to the variable $headers.
The while loop uses mysql_fetch_row() function to extract data from the array $result. Then for each record, an email is generated and sent to individual recipients.
This finishes the "Publishing Newsletter Using PhP & MySQL" series. I hope I was lucid enough to enable you to maintain your own newsletter. This was just a framework. I suggest you keep tweaking the code according to your requirement and taste. You are always welcome to write to me using the form at http://www.bytesworth.com.
Stay tuned for more articles.
==========================================================
Amrit Hallan is a freelance web developer. You can checkouthis website at http://www.bytesworth.com. For more such articles join BYTESWORTH REACHOUT at http://www.bytesworth.com/br/default.asp or if you have a web dev related question then post it at http://www.business180.com/index.php
==========================================================
The time has arrived to launch your publishing career at last. The subscribers have subscribed and your emails have been validated. Now all you have to do is, write the newsletter, copy/pase it in the box and click the submit button
We can publish text newsletter as well as HTML newsletter. We'll see how.
First the form:
<form method="post" action="send_newsletter.php">
Subject:<br>
<input type="text" name="sub" size="40"><br>
Body<br>
<textarea cols="80" rows="20" name="bdy" wrap="hard"></textarea><br>
HTML: <input type="checkbox" name="html" value="0"><br>
<input type="submit" name="s1" value="Submit">
</form>The form has three fields, namely, Subject, Body and a checkbox to decide whether you want to send a plain newsletter or an HTML newsletter. This form uses the file "send_newsletter.php" to send the newsletter. Here's send_newsletter.php:
<?php
$html=$_POST[html];
$db=mysql_connect("localhost", "wwwdate_betty", "soandso") or die("I cannot
connect to the database because " . mysql_error());
mysql_select_db("wwwdate_others", $db);
$query="select name, email from subscribers where active=1";
$result=mysql_query($query);
$subject=$_POST[sub];
$tb=stripslashes($_POST[bdy]);
if($html==NULL)
{
$headers="From: "DATEONLINE-U.COM" <dc@dateonline-u.com>";
}
else
{
$headers="From: "DATEONLINE-U.COM" <dc@dateonline-u.com>n";
$headers.="MIME-Version: 1.0n";
$headers.="Content-type: text/html; charset=iso-8859-1";
}
?>Most of the initial code must be clear by now. If not, please refer to the links mentioned at the beginning of the article. We use the function stripslashes() to take care of all the characters that PHP finds unpalatable (such as double-quotes and single-quotes). The if condition checks whether you have selected the HTML checkbox. If yes, then the necessary encoding is added to the variable $headers.
<?php
while($row=mysql_fetch_row($result))
{
$tbody="Dear " . $row[0] . ".rnrn";
$tbody.="Here's the current issue of DATE IS THE CASE dated " . date
("m-d-Y", time()) . "rnrn";
$tbody.=$tb;
mail($row[1], $subject, $tbody, $headers);
}
echo "<h1>Done!</h1>";
?>The while loop uses mysql_fetch_row() function to extract data from the array $result. Then for each record, an email is generated and sent to individual recipients.
This finishes the "Publishing Newsletter Using PhP & MySQL" series. I hope I was lucid enough to enable you to maintain your own newsletter. This was just a framework. I suggest you keep tweaking the code according to your requirement and taste. You are always welcome to write to me using the form at http://www.bytesworth.com.
Stay tuned for more articles.
==========================================================
Amrit Hallan is a freelance web developer. You can checkouthis website at http://www.bytesworth.com. For more such articles join BYTESWORTH REACHOUT at http://www.bytesworth.com/br/default.asp or if you have a web dev related question then post it at http://www.business180.com/index.php
==========================================================
COMMENT ON THIS ARTICLE...
No comments yet. Be the first one to comment.
Effective Search Engine Use
A Reality Check Is Necessary Before Starting A Home Business
Power Words And Phrases
A Reality Check Is Necessary Before Starting A Home Business
Power Words And Phrases
SEO Articles
Internet Marketing Articles
Development Articles
General Articles
And also in our Archives
Internet Marketing Articles
Development Articles
General Articles
And also in our Archives
Drive traffic to your business and get recognized as an industry leader by sharing your knowledge on Site-Reference. Authors are given a wide range of exclusive benefits here at SR; so checkout what we can offer to those that…

We’re always on the lookout for new writting talent so even if haven’t written for the web yet, feel free to contact us anytime
We’re always on the lookout for new writting talent so even if haven’t written for the web yet, feel free to contact us anytime




