Creating the Interface
Now we're going to create an e-mail script with a web interface from which you
can edit each of the header fields we've examined and send a customized e-mail.
The script will make use of seven custom functions and a global variable
$action, which when specified tells the script which
action should be taken.
1. First we'll make a new text file called simple_mailer.php. Then we'll define the
mailer_header(), which simply starts an HTML page:
2. Next, to end an HTML page, we have
mailer_footer():
3. We define
error_message() to report errors using the JavaScript
alert() method:
4. Similarly, we have
user_message() to report the
result of an action, once again using the JavaScript
alert()
method:
5. The main web interface for sending e-mail is displayed by
mail_form():
6. In
send_mail(), we define a wrapper function that calls
my_mail() and reports the result:
7. We shall use
my_mail() to actually send the user-defined e-mail:
8. Finally, we have a switch block that uses our global variable
$action
to determine which functions to call. If
$action is unspecified, we default
to the
mail_form() function:
9. Save the finished script as simple_mailer.php and upload it to your server.
10. Here's a sample run of the script. The
mail_form()
function displays a web-style user interface for sending an e-mail:

Launch this page
Now we're going to work up to adding more functionality to our e-mail script by exploring
MIME (Multipurpose Internet Mail Extensions) and content-types in
Part 4 >>