Free Webmaster Resources .info
PHP Introduction and Tutorials Javascript  Introduction and Tutorials HTML  Introduction and Tutorials ASP  Introduction and Tutorials Free Internet Access Guide and Directory Webspace  Directory Webhosting  Directory Adult Webhosting  Directory PHP Hosting  Directory ASP Hosting  Directory
à Navigation
» Home
» Php Introduction
» Php Tutorials
» Submit Scripts
 
Subscribe for free!

Join our mailing list today and recieve free updates monthly with web hosting specials!
 
 

 

 

Free Webmaster Resources .info | Free PHP Tutorials


Mailing List in PHP

Now for the fruits of your labour , create a newsletter and send it to all your subscribers. First of all we create a form with some necessary fields in it .

<form action = "sendnewsletter.php" method = "post">
<table>
<tr>
<td>Subject : </td>
<td>
<input type = "text" name = "subject" size="70">
</td>
</tr><tr>
<td>Body : </td>
<td><textarea name = "body" cols = "50" rows = "20" wrap = virtual></textarea></td>
</tr><tr><td>
<input type = "submit" value = "create newsletter">
</td><td>
<input type = "reset">
</td></tr>
</table>
</form>

Pretty straightforward this now for the script to send the newsletters

<?php
//sendnewsletter.php
//creates your newsletter an sends it.
if (($subject == "") || ($body == ""))
{
header("Location : sendaletter.php");
exit;
}
else
{
//make a connection
$connection = mysql_connect("localhost" , "username" , "password")
or die("cannot make connection");
//select the database
$db = mysql_select_db("email" , $connection)
or die("cannot find database");
$sql_query = "SELECT email FROM email";
$result = mysql_query($sql_query) or die("cannot execute query");
$header = "From : Myscripting.Com";
//loop through rows
while ($row = mysql_fetch_array($result))
{
$address = $row[0];
//mail function requires email address($address)
//The subject($subject) , the message ($body) and
//the $header info
mail($address ,$subject , $body , $header);
//display a message confirming email has been sent
echo ("newsletter sent to : $address<br>");
}
echo ("Completed sending emails");
}
?>

Remember and add your user info at the start , the hostname , username and password.

This script simply sends an email to an address forom the database , it loops through all stored addresses dispalying a confirmation message and when this is finished you get a message .

Note the if else at the start is our first validation this basicly checks whether you have entered and data for the subject and the body , if you have not you are redirected back to the form.

<Top | Back


Recommended Webhosting Company
Find free web hosting
Looking for free web hosting? Review and compare FindStuff's comprehensive resources. Search now!

 

 
Related Websites
 


Free Email
Your source to free email.

Free Casino Downloads
Contains useful free casino downloads.

Free Software Downloads
A complete collection of free software downloads.

Free
Download free stuff from psike.com your free stuff resource.

Free Teen Online Dating
Meet other singles for free online dating.

Coolfreeweb.com
The Free category at coolfreeweb.com

My Directory Listing
A massive directory listing of websites

Website Collation Project
The website collation project contains a huge directory of websites.


 
Top Webhosts
 
 1. Find free web hosting
 2. Web Hosting
 3. Free Web Hosting
 4. Free Web Hosting
 5. Web And Hosting
 
-
- Give us feedback
 
Last updated
Oct 11, 2008
Free Webmaster Resources .info | A resource must for every web master
Untitled Document - Web Hosting
- PHP Hosting
- Free Internet Access