Creating the admin send mail form
Now that the login to the admin is successful and we have a secure environment, I need to make a form to be able to send mail to those on my list when indeed I do release new php scripts. My admin form will look a lot like the mail-to form (12/28/99) except it will have a few modifications:
I am going to use a loop to send the mail instead of simply separating the cc email addresses by commas so people on the list cannot use what I think is an abused mail function "reply to all." You could easily alter the code below to not use a loop to send mails out. I'll leave that one to you to do if you want that option with your mail list. I have disabled the email send function in this example, and also the emails are not really the emails in the actual list. However you should note the loop that creates the dropdown select list dynamically. This will list all the emails in the list (which in the example below are actually bogus email addresses, which I have done of course for privacy reasons). You would only need to point the script to the proper filename on your php-enabled server and it would function fine. First let's look at the admin form:
Example #19: the complete TD Subscribe Mail administration HTML
|
Now you would make a separte HTML page for the above tabled form and put it in a protected admin directory. Here is the HTML and PHP code for this page. To make it easier to follow I put the PHP code in blue, the HTML in black, and the HTML form path code in red. This is also an example of how to move in and out a loop using PHP and HTML to print a dynamic sorted drop-down list. Now every time you login to your admin area, you will have a real-time updated list of email addresses.
<html>
<head>
<title>TD Subscribe Mail Script (ADMIN AREA)</title>
</head>
<body>
<div align="center"><center>
<table border="0" width="60%"
bgcolor="#B5DBDA"><tr>
<td width="100%"><p
align="center"><big><strong>
<font color="#000000" face="Arial">TD Subscribe Mail
Administration</font>
</strong></big></p>
<form method="POST" action="
/PATH_TO/subscribe.php3"><div
align="center"><center><p><font face="Arial"
color="#0000FF">Add/Remove A Subscriber</font>
<br><input type="text" name="from"
size="20"><font face="Arial"><font
color="#FFFF00">
<input type="radio" value="yes" name="subscribe"
checked></font><font color="#000000"><small>subscribe
</small><input type="radio" value="remove"
name="subscribe"><small>unsubscribe </small></font></font>
<input type="submit"
value="Submit"></p></center></div>
</form>
<form action="
PATH_TO/admin_mail.php3" method="POST">require("setup.php3");
$toemails = file("$mail_list_path/phpelist.txt");
sort($toemails);
for($index = 0; $index < count($toemails); $index++)
{
?>
<option value="<?$toemails[$index]; print("\">$toemails[$index]</option>");
}
?>
</select>
<br><small>Subject:<input type="text"
size="28" name="subject"
value="New PHP Scripts Released!"></small></font></p>
</div><div align="center"><center><p><font
face="Arial"><textarea name="contents" rows="5"
cols="64"></textarea><br>
<small>Enter your message body above</small> <input type="submit"
value="Submit">
<input type="reset"
value="Reset"></font></p></center></div><div
align="center">
<center><p><em>The following message is added to the bottom of each
email<br>
(NOTE: the unsubscribe code will be filled by the script
automatically):</em></p>
</center></div><div
align="center"><center><p><font
face="Arial"><small>-------------------------------------------------------------------------------------</small><br>
<small>This email is not spam. You signed up for this<br>
opt-in email list at php-scripts.com </small><br>
<small>If you would like to unsubscribe from the
php-scripts.com</small><br>
<small>script update opt-in email list, just click the link
below</small><br>
<a
href="http://www.php-scripts.com/php_diary/unsubscribe.php3"><small>
http://www.php-scripts.com/php_diary/unsubscribe.php3?id=</small></a><br>
<small>if the link above does not show in your email</small><br>
<small>program just cut and paste it to your browser</small><br>
<small>-------------------------------------------------------------------------------------
</small></font></p></center></div>
</form>
</td></tr>
</table>
</center>
</div>
</body>
</html>
Notes: You might see that I am also using a function we haven't covered called require. Those that know the Perl world will recognize this. require is similar to the include function, however there is one very big difference: using require PHP will always compile the file and include will only be compiled if necessary (IE. you used include in a loop where if($x = 1) {include "this file"}. In the case above I am using a separate file called setup.php3 to hold my path information. The use of require and include might be confusing to you, but generally it is best to use include inside of loops or when you may or may not need the information from an external file, however use require when you always will need the information contained in an external file. Thus far I have used include for various things like my daily background changing and date the page was last modified when I could (and probably should) have used require. Another new function is called sort, which will sort the email addresses contained in the array by ASCII. There are other sort options available that we will get into more depth with later, but I will give you a brief rundown on them now:
sort - sorts from a - z or numerically from LOWEST to highest
rsort - sorts from z - a or numerically from HIGHEST to lowest
It is worth further noting that sorting is done in ASCII order and this is not the same as case insensitive sorting. So if you had state and State, they would not both be sorted under "s." You would need a more sophisticated sorting algorithm for this.
Tomorrow, I will be able to finish the code for the administration area and the mail list script. Please vote on what you think of this diary lesson :)
[back]
01/01/00 "Sending mail to the mail list"
[next]
PHP Diary | PHP Housekeeping | PHP Scripts | TD Scripts.com
Copyright 2000 php-scripts.com Last Modified 01/6/00 05:30