MIME Mail and SMTP Classes
By Devin Doucette
Copyright (c) 2004 Devin Doucette
There are two classes involved here. The first is mimemail, which is
used to create email messages with varying levels of complexity. The
second is smtpmail, which connects to an SMTP server and sends the
emails that have been created with mimemail. I will explain both
classes briefly below, and attach an example in another file.
When you set the HTML section of the email, it will parse the HTML and
automatically embed any files into the email that are on the server
that is sending the email. This only applies to files with the following
extensions: gif, jpg, jpe, jpeg, png, bmp, tif, tiff, swf, wav.
If you wish to modify this behavior, edit the $filetypes array in the
If an error occurs in either class, it will be added to the error array
contained within each class.
Here is a short overview of all the functions that you may need to call
from the mimemail class:
Call this before you send the email to compile all its parts
(Optional if using setplain instead)
Sets the HTML version of the email
$data is a string containing HTML
(Optional if HTML version was already set)
Sets the plain text of the email
$data is a string containing plain ASCII-encoded text
(Optional) Set the character set being used
Example: setcharset("iso-8859-1") [Which is the default]
Set sender address using:
$email is a string containing the address, $name (which is optional) is
the name of the person who is sending the email.
(Optional) Set return address using:
Same arguments as for setsender
Set subject using:
$data is a string containing the subject
Add recipients using:
$email is a string containing the address
Valid values for $type are "To", "Cc", and "Bcc"
(Optional) Set X-Mailer using:
$data is a string containing the value you wish to send for X-Mailer
Add attachments using:
To add a file from disk, just pass the file name with no value for data.
To add a file from memory, pass the file name you want, and pass the data as $data.
Here is a brief overview of the smtpmail class:
This is the constructor
$hostname is the host name of the SMTP server you're using
$smtpport only needs to be set if it is not 25
Use this function to send mail:
$headers and $message are the $headers and $message member variables of
the mimemail object that you have created. Be sure to call openconnection
before attempting to send mail.
Call this to open the connection to the server
Call this to close the connection to the server