lib 开源代码
来源:互联网 发布:秦皇岛相对湿度数据 编辑:程序博客网 时间:2024/05/16 17:08
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鏰is
You can help by translating this documentation; contact me for the the doc source.
Informations
Version : 1.3
Licence : GPL
Lastmod : Nov 2001
Author : Leo West
Installation
Download libmail.zip
Content
No specific configuration is required in the library itself.
In php3.ini (php.ini for PHP4):
Documentation
- Synopsis
- Constructor
- Subject( string sujet )
- From( address )
- To( mixed address )
- CC( mixed address )
- BCC( mixed address )
- Body( string body, [string charset] )
- Attach( string filename, [string mimetype], [string disposition] )
- autoCheck( boolean )
- Organization( string $org )
- ReplyTo( string address )
- Priority( integer $priority )
- Receipt()
- Send()
- Get()
- Some advices
- Howto send a mail in HTML format
- ChangeLog
Synopsis
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);
$m->Attach( "/home/leo/toto.gif", "image/gif", "inline" );
echo "Mail was sent:"
echo $m->Get(); // show the mail source
Constructor
Create an instance of a Mail.
$mail = new Mail();
Subject( string sujet )
Defines the mail subject line. optional.
$mail->Subject( "Bonjour, monde" );
From( address )
Defines the mail sender. call required.
$mail->From( "me@isp.com" );
To( mixed address )
Defines the recipient(s). call required.
The address parameter can be either an adress (string) or an array of addresses.
$tos = array( "you@isp.com", "u2@isp.com" );
$mail->To( $tos );
CC( mixed address )
Defines one or many Carbon-copy recipients.
The address parameter can be either an email adress (string) or an array of addresses.
$adr_en_cc = array( "a@isp.com", "b@isp.com", "c@isp.com" );
$mail->CC( $adr_en_cc ); // many recipients in CC
BCC( mixed address )
Defines one or many invisible carbon-copy recipients.
The address parameter can be either an email adress (string) or an array of addresses.
$adr_en_bcc = array( "a@isp.com", "b@isp.com", "c@isp.com" );
$mail->BCC( $adr_en_bcc ); // many recipients
Body( string body, [string charset] )
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 avé dé accents", "iso-8859-1" );
Note: Don't send HTML this way. See Some Advices to send a mail in HTML format.
Attach( string filename, [string mimetype], [string disposition] )
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.
$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" );
autoCheck( boolean )
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 isnot checked.
Important : When on, any unvalid address will display an error message andstop 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
Organization( string $org )
Defines the Organization field. Optionnal.
$mail->Organization( "My company" );
ReplyTo( string address )
Defines a "Reply To" address that is different than the Sender address.
$mail->ReplyTo( "helpdesk@mycompany.com" );
Priority( integer $priority )
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.
$mail->Priority( 3 ); // normal
$mail->Priority( 5 ); // pas urgent du tout
Receipt()
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()
Send the mail.
Don't forget to call this method :)
Get()
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.
// display (not nicelly) the message on the page
echo "Your message has been sent:", nl2br( $msg );
// 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" );
Some advices
Howto send a mail in HTML format
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:
$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 :
- rewrite them in absolute : /mahomepage.html becomes http://chez.moi.com/mahomepage.html
- define a BASE HREF in the HEAD section. All relative links will be relative to this URL
When your recipients don't have any web access, you have a few solutions left such as thedata: URLs that i describe http://lwest.free.fr/doc/php/smp/?docid=data_url
or the linked parts ( documented somewhere on Zend.com )
ChangeLog
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()
- lib 开源代码
- 如何获得GCC lib 的开源代码?
- shopxx源代码lib
- 调试Lib文件无法进入源代码
- Hadoop源代码分析(mapreduce.lib.partition/reduce/output)
- Hadoop源代码分析(mapreduce.lib.partition/reduce/output)
- Hadoop源代码分析(包mapreduce.lib.input)
- Hadoop源代码分析(包mapreduce.lib.map)
- Hadoop源代码分析(mapreduce.lib.partition/reduce/output)
- Lib
- lib
- lib
- lib
- 开源代码
- 开源代码
- 开源代码
- 使你的工程脱离OpenCV安装环境及lib独立编译(源代码编译)
- TVSKIN源代码阅读日记(五)--- CFONT CLASS (MFC LIB) & LOGFONT STRUCT(GDI)
- C语言和设计模式(之原型模式)
- 后台服务器经典面试题
- Left join
- 黑马程序员---集合
- 前端开发网站
- lib 开源代码
- 大话设计模式之责任链模式(Chain of Responsibility Pattern)
- Ubuntu 10.04 下编译pgAdmin3-1.14.1
- Linux的安装和分区
- #define new DEBUG_NEW
- Kd-tree之初见
- 在别的函数或者线程函数里使用 PostMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)小收获
- 如何成为一名C++程序员
- document.getElementById的简写方式