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.
Now our new interface looks like this:

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 >>