Writing a mailing list program with php/mysql.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

I've written a mailing list form for a website. It currently works by having
the subscriber check up to 3 checkboxes depending on the mailing list they
want to sign up for (prayer, newsletter and announce). They then type their
email address into the "email address" field and click the subscribe button.
After they do that, the php script will check the form for validity and
return error if not filled out the right way or it will send an email to me
if it "worked" (in the sence that the form was filled out by the user the
right way). What I need to know is: given the code below, are there any
examples of php/mysql driven mailing list scripts that I can use as a
tutorial on helping me to convert mine to a mysql database driven program?
Any ideas/recommendations would be apreciated. Thanks for all the help.

The code below if copied and pasted into their own seperate files should
work on any apache/php 5.0.5/mysql 3.xx server.

mailing_list.html:
this file was included in the home page of the website with include().
[code]
<form action="script/mailinglist.php" method="post">
<table border="1" cellspacing="0" cellpadding="2" style="border-color:
#600;">
<tr><th style="background-color: #600; color:#fff; text-align: center;
padding: 0 10px;">Sign up for the mailing lists!</th></tr>
<tr><td>
<input type="checkbox" name="prayer">E Prayer <input type="checkbox"
name="news">E News <input type="checkbox" name="announce">E Announce
</td></tr>
<tr><td style="background-color: #fff; text-align: center; padding: 0
10px;">
<p style="margin-bottom: 0;">
Your email address: <input type="text" name="email"><br>
<input class="button" type="submit" value="Sign up now!" /><br />
</p>
<a href="comunity.php">Go to the Online Comunity page to find out
more!</a><br>
</td></tr>
</table>
</form>
[end of mailing_list.html code]

list_functions.php: the user defined functions created to use in
mailinglist.php.
[code]
<?php
//checkemail checks an email address to see if its valid
//true if valid and false otherwise
function checkemail($email){
if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,3})$', $email)) {
return $email; }
else {return false;}}

//checklist checks that at least 1 mailing list exists
//returns a string containing mailing lists signed up for or null if none
checked
function checklist($list1, $list2, $list3){
if($list1=="on"){$final="Prayer\n";}
else {$final="";}
if($list2=="on") {$final.="News\n";}
else {$final.="";}
if($list3=="on") {$final.="announce\n";}
else {$final.="";}
return $final; }

?>
[end of list_functions.php code]

mailinglist.php: the actual mailing list script code. called by
mailing_list.html above.

[code]
<?php
//mailing list script
//turn error reporting off
//error_reporting('E_ALL');
include_once("list_functions.php");

//check to see what lists are being signed up for
//if no lists are checked an error shows
$list=checklist($_POST['prayer'], $_POST['news'], $_POST['announce']);

//now check the email address
$mail=checkemail($_POST['email']);

//check to see if both email and list are filled in the right way
//if not give an error
if
((!$mail && !$list)||
(!$mail || !$list)){?>
<script language="javascript">
alert('Please select at least 1 mailing list to sign up for and make sure
you have entered a valid email address');
history.back();
</script>
<?php }
//send the user a message and send the email
else { ?>
<script language="javascript">
window.location='../success.php';
</script>
<?php
//now send the email

//this is the email message that will be sent
$message=$mail." would like to be signed up for the ".$list." mailing
lists\r\n";
//send the email now
mail("subscribe@xxxxxxxxxxxxxxxxxxx", "mailing list request", $message,
"From: <mailing list form>MailingListForm@xxxxxxxxxxxxxxxxxxx");
?>
<script language="javascript">
history.back();
</script>
<?php } ?>
[end of mailinglist.php code]

Sorry for the extensive content of this message but I wanted to cover
everything I could from the beginning.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux