This library offers an object oriented way to send email from a PHP program.
Important! users of 1.2 version , download the last version. A bug in v1.2. was impacting file attachment functionnality.
Some of the libMail functionalities are :
version 1.3
version 1.2
version 1.1
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" ); // set the body $m->Cc( "someone@somewhere.fr"); $m->Bcc( "someoneelse@somewhere.fr"); $m->Priority(4) ; // set the priority to Low $m->Attach( "/home/leo/toto.gif", "image/gif", "inline" ) ; // attach a file of type image/gif to be displayed in the message if possible $m->Send(); // send the mail echo "Mail was sent:<br><pre>", $m->Get(), "</pre>";
Download libmail.zip
Content:
No specific configuration is required in the library itself. In php3.ini (php.ini for PHP4):
SMTP = smtp@isp.com ; for win32 only sendmail_from = valid_address@chezmoi.fr ;for win32 only
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.
$mail->To( "you@isp.com" );
$tos = array( "you@isp.com", "u2@isp.com" ); $mail->To( $tos );
Defines one or many Carbon-copy recipients. The address parameter can be either an email adress (string) or an array of addresses.
$mail->CC( "toto@somehost.fr" ); // un seul destinataire en CC
$adr_en_cc = array( "a@isp.com", "b@isp.com", "c@isp.com" ); $mail->CC( $adr_en_cc ); // many recipients in CC
Defines one or many invisible carbon-copy recipients. The address parameter can be either an email adress (string) or an array of addresses.
$mail->BCC( "manager@somehost.fr" );
$adr_en_bcc = array( "a@isp.com", "b@isp.com", "c@isp.com" ); $mail->BCC( $adr_en_bcc ); // many recipients
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.
$mail->Body( "Message in english" ); $mail->Body( "Message avé dé accents", "iso-8859-1" );Note: Don't send HTML this way. See Advices to send a mail in HTML format.
Attach a file $filename to the mail.
// le fichier se trouve dans le repertoire courant $mail->Attach( "logo.gif", "image/gif" );
// fichier indique en absolu - affiche sous forme de lien par le client mail $mail->Attach( "C:\\Mes Documents\\resume.doc", "application/x-msword", "attachment" );
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.
$mail->autoCheck( false ); // unactivate the validation $mail->autoCheck( true ); // activate the validationImportant : 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)
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 usuall used by mail clients, eg. by highlighting urgent messages.
$mail->Priority( 1 ); // urgent $mail->Priority( 3 ); // normal $mail->Priority( 5 ); // pas urgent du tout
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.
$mail->Receipt();Warning: this mecanism is not standardised, thus not fully supported by mail clients.
Send the mail. Don't forget to call this method :)
$mail->Send();
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.
$msg = $mail->Get();
// display the message on the page echo "Your message has been sent:<br><pre>", nl2br( $msg ) , "</pre>";
// log it in a database $msg = str_replace( "'", "''", $msg ); $bdd->exec( "insert into Mailbox( user, folder, message, senttime ) values ( 'toto', 'Sent', '$msg', $FCT_CURRENT_TIME" );
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:
$file = "mail.html"; $mail->Body( "This mail is formatted in HTML - shame on me" ); // inline intructs the mail client to display the HTML if it can $mail->Attach( $file, "text/html", "inline" );If your HTML page contains some images or links don't forget either to :
<head> <base href="http://chez.moi.com/"> </head>
Name | libmail |
Lang | php3 / php4 |
Version | 1.3 |
Lastmod | Thu Oct 12 12:12:36 UTC 2000 |
Author | Leo West |