Home arrow PHP arrow Page 5 - Creating a Mailing List Manager with PHP

Autoresponders - PHP

This tutorial will guide you through building a complete mail list administration solution in PHP, capable of handling multiple lists.

  1. Creating a Mailing List Manager with PHP
  2. Creating the front page
  3. Adding names to the list
  4. Editing the names
  5. Autoresponders
  6. Conclusion
By: Duncan Lamb
Rating: starstarstarstarstar / 52
December 16, 1999

print this article



Autoresponders are mechanisms that automatically email a message to a user when a certain event is completed. Usually, this would be when a new user signs into the list by using a form. To edit the autoresponder, a technique similar to what we used to edit addresses will be used:


<html><head><title>Edit Maillist addresses</title></head><body> <form method=post action="writeautoresponder.php3"> <br> This is the automatic message sent to people who submit their name to the Test List mailing list. See Page 5 in the tutorial to see an example of using this feature. <br><br> <textarea cols=70 rows=20 name="Body"> <? readfile("data/autoresponder.txt"); ?> </textarea> <br><br> <input type="submit" name="submit" value="Save This List"></FORM> <br><br><a href="addnames.php3">Add names to a list</a>. <br><br><a href="data/log.txt">View Send Log</a>. <br> </body></html>
And then the form saves our changes:


<html><head><title>Updating file....</title></head><body> <br><br> <b>The following autoresponder message has been saved:</b><br> <? $myfile = fopen("data/autoresponder.txt","w"); fputs($myfile,$Body); fclose($myfile); ?> <br> <pre><? echo $Body ?> </pre><br> <br> <a href="index.php3">Home.</a> </body></html>
To activate it, create a code snipet which will put a small form on any page you choose. Something similar to this would work anywhere:

<b>Get notified of updates by email:</b><br> <form method="post" action="thanks.php3"> <input type="text" name="Email" size="20"> <input type="submit" Value="Subscribe"></form>
All thatís left is a processing and Thank You page, which borrows code from the other pages made earlier:


<html><head><title>Thanks!</title></head><body> <? $Body = readfile("data/autoresponder.txt"); mail("$Email","Welcome to my mailing list!", "$Body","From: Me\nReply-To: me@myaddress.com"); $myfile = file("data/mylist.lst"); $fh = fopen("data/mylist.lst","w"); for ($index=0; $index < count($myfile); $index++) { if ($Email != chop($myfile[$index])) {fputs($fh,$myfile[$index]);} } fputs($fh,$Email."\n"); fclose($myfile); ?> Thank you! <br><br> <a href="index.php3">Home</a>. </body></html>
Note line 4 Ė itís a lightly documented trick that allows you to read an entire file into a variable, which is exactly what we need to do here. Of course, if you use this script yourself, it will probably be in another directory, so watch your paths. Also note this is just for one list Ė what would you need to do to make multiple autoresponders?

And thatís it! Now your new members will immediately receive a welcome message, or be sent important info, receive a joke of the day, or whatever else you can dream up!

>>> More PHP Articles          >>> More By Duncan Lamb

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: