An object oriented way to send email from a PHP program.
Some of the libMail functionalities are :
o Sending one or more file in attachment
o Specify one or many recipients in To, CC or BCC
o Format a message "ready to send" without sending it immediately
o Auto checking of email addresses syntax
o Add a receipt to the mail
This documentation is available in english | français
You can help by translating this documentation; contact me for the the doc source.
Version : 1.3
Licence : GPL
Lastmod : Nov 2001
Author : Leo West
Download libmail.zip
Content
libmail.php | the Mail component |
libmail_fr.html | documentation in french |
libmail_en.html | documentation in english |
No specific configuration is required in the library itself.
In php3.ini (php.ini for PHP4):
configure the sendmail address code;for win32 only> |
|
configure the SMTP server host code |
|
include "libmail.php";
$m = new Mail(); // create the mail
$m->From( "leo@isp.com" );
$m->To( "destination@somewhere.fr" );
$m->Subject( "the subject of the mail" );
$m->Body( "Hello\nThis is a test of the Mail component" );
$m->Cc( "someone@somewhere.fr");
$m->Priority(4);
// | attach a file of type image/gif to be displayed in the message if possible |
$m->Attach( "/home/leo/toto.gif", "image/gif", "inline" );
$m->Send(); | // send the mail |
echo "Mail was sent:"
echo $m->Get(); // show the mail source
Create an instance of a Mail.
$mail = new Mail();
Defines the mail subject line. optional.
$mail->Subject( "Bonjour, monde" );
Defines the mail sender. call required.
$mail->From( "me@isp.com" );
Defines the recipient(s). call required.
The address parameter can be either an adress (string) or an array of addresses.
Defines one or many Carbon-copy recipients.
The address parameter can be either an email adress (string) or an array of addresses.
Defines one or many invisible carbon-copy recipients.
The address parameter can be either an email adress (string) or an array of addresses.
Defines the message body. the optional charset parameter defines the character set used in the message.
The default is "us-ascii". Use iso-8859-1 charset if your message includes european characters such as accents.
Attach a file $filename to the mail.
filename : path to the file on drive.
mimetype : string that defines the file MIME-type.
Default MIME is 'application/x-unknown-content-type'.
The Mime-Type is used by Email clients, for instance to display an image attached in the mail,
or to "automagically" launch an attached virus for some of them :)
disposition : this code defines the method used to display the attachment.
With inline (default), the mail client will display the file directly in the mail if possible.
With attachment, the attched file will be presented as a link.
Activate or not the recipients email addresses validation. Default on.
The validation is only a syntax one - the fact that this address exists or not is not checked.
Important : When on, any unvalid address will display an error message and stop the script.
You can change this "safe mode" by :
a) modifying the CheckAdresses() method.
b) manually checking the addresses before and invoking AutoCheck(false)
$mail->autoCheck( false ); // unactivate the validation
Defines the Organization field. Optionnal.
$mail->Organization( "My company" );
Defines a "Reply To" address that is different than the Sender address.
$mail->ReplyTo( "helpdesk@mycompany.com" );
Defines the mail priority. Optional.
Priority must be an integer between 1 (highest) et 5 ( lowest )
This information is usually used by mail clients, eg. by highlighting urgent messages.
Add a receipt to the mail.
This is a mecanism that sends a receipt back to sender when the message is opened by a recipient.
The receipt is sent to the address defined in From field, unless if ReplyTo field is defined.
As this mecanism is not standardised, it is not always supported by mail clients.
$mail->Receipt();
Send the mail.
Don't forget to call this method :)
Return the whole email (headers + message + attachments) in raw format.
Can be used to display the mail, or to save it in a File or DB.
Fist point: I personally hate receiving HTML mails: I *don't* recommend to use it.
To send a HTML mail with libMail, you must attach your HTML source as a file:
version 1.3
o BUG FIX - file attachment didn't work
o serious rewrite of the class
o small optimization in _build_attachement()
version 1.2
+ added ReplyTo( $address ) method
+ added Receipt() method to add a mail receipt
+ added optional charset parameter to Body() method . should fix charset problem on some mail clients
version 1.1
+ optional mimetype and disposition parameters to Attach() method
o fixed parenthesis bug in sizeof()