SENDING RICH EMAIL WITH PHP Article by Carrie Sucharski
MM320: Dynamic Web Applications
Instructor: Aarron Walter
CODE SPOT : Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Sources
 
Part 3: Creating an E-Mail Interface

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:

Screenshot of the E-Mail form
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 >>

Article Last Updated on February 04, 2012 @ 2:30 pm
Inside This Lesson
+ Part 1 PHP and MySQL

+ Part 2 Sending Simple E-Mail

+ Part 3 Creating an E-Mail Interface

+ Part 4 Understanding MIME Types

+ Part 5 Attaching Files to E-Mail


More Articles


Live Discussion
PHP Templates
:: This website was developed by Carrie Sucharski © 2003 ::

E-Mail: royaltyrate@yahoo.com
Portfolio: http://vintagestars.com/aia/