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 5: Attaching Files to E-Mail

Making Our E-Mail More Advanced

We're going to take our previous script (simple_mailer.php - part 3) and add some extra input fields into the user form, so that they can control their MIME preferences and attach files. We are going to add 3 new functions:

· mail_type - To specify whether the message contains a text/plain (default) or text/html media type, which allows the user to send an HTML e-mail. If the user attaches a file to the e-mail, the form will default to text/plain regardless of the user's choice.
· mail_encoding - To specify whether the message contains 7bit (default) or 8bit data.
· userfile - To allow the user to upload a file from their computer and attach it to an e-mail.

Modifying the Original Code

As we modify the code from the mail_form() function, save the newly modified script as adv_mail.php.



New Code:



Now our new interface looks like this:

Screenshot of the Advanced E-Mail form
Launch this page



Next we have to modify the send_mail() function to include our new variables in the $mail_parts associative array. We also have to add MIME-specific headers and content to correspond to the options specified on the form by the user. The new code will look like this:



So there you have it! An advanced e-mail form that can handle headers, content types, file attachments, and messages of unlimited length.


This article referenced a number of Sources and Credits >>

Article Last Updated on July 31, 2010 @ 1:16 am
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/