祝大家新年快乐!新年新气象!

pear mail类 demo

上一篇 / 下一篇  2007-04-27 01:58:50 / 个人分类:php

PHP PEAR MAIL发送TEXT/HTML格式邮件
PHPChina 开源社区门户#MA$CIzw

一 TEXT格式
o0{3q4z+{ XU"}0邮件发送方式有3种
y7MpE7E6?s7y0* mailPHPChina 开源社区门户pN{ XL]N
    If safe mode is disabled, $params will be passed as the fifth argument to the PHP mail()
-i?e0^p4_V8Ciy0    function. If $params is an array, its elements will be joined as a space-delimited string.
X1AsF2n#O)Z+AYA0* sendmailPHPChina 开源社区门户/tOq!l X/[
    $params["sendmail_path"] - The location of the sendmail program on the filesystem.
PQ.S)Wz ~Kg%P*|0    Default is /usr/bin/sendmailPHPChina 开源社区门户VpOpP wS
    $params["sendmail_args"] - Additional parameters to pass to the sendmail program.
-_2N+Z.KV!Q"m8tt0* smtp
Q|*ay7`(OciM'o0    $params["host"] - The server to connect. Default is localhostPHPChina 开源社区门户~#kHD;V,c
    $params["port"] - The port to connect. Default is 25
T^2J,t-JJ0    $params["auth"] - Whether or not to use SMTP authentication. Default is FALSEPHPChina 开源社区门户/|9[da ov
    $params["username"] - The username to use for SMTP authentication.
H S/}EN0    $params["password"] - The password to use for SMTP authentication.PHPChina 开源社区门户tF+M{,`gF

PHPChina 开源社区门户/@0t2Ic#FF`}

!pfFE t'Ds:vc&f!X0<?phpPHPChina 开源社区门户r+Ut,I7N7R__
require_once('Mail/Mail.php');PHPChina 开源社区门户AKc(mK5|Z:u
$recipients         ='111@111.com';
1V t'm(a"vRUK6b\0$headers['From']    ='111@111.com';PHPChina 开源社区门户^b WQ)M7N9T(VI
$headers['To']      ='111@111.com';
L;k;jC'q`Gr@9h0$headers['Subject'] = 'Test message';PHPChina 开源社区门户$qwAWj


e2C3RH'~V@0PHPChina 开源社区门户I&}:ll }"AV/Ky.z

$body = 'Test message';

J{6fe ?0
{ m3e9av*U\k8j0

tq8x iO!gX0$params['username'] ='111@111.com';
?2v9V-ii(uL q#C0$params['password'] = '111';
5A(F,N kffr0$params['auth'] = true;

,a(w+R DZlto0PHPChina 开源社区门户/p0Y8f/vt

^EBB^9a$K `0// Create the mail object using the Mail::factory method
b0b)d$^&ENP` l9c0$mail_object =& Mail::factory('mail', $params);

B)[R8O x F0PHPChina 开源社区门户sjm)s#ek9wv h

;B+vrZ6M'T7jf w0$mail_object->send($recipients, $headers, $body);
%_ ^]5^Gj0?>PHPChina 开源社区门户P-^bM)Ul)w

PHPChina 开源社区门户&EtT _:~;N

oW{ ZU X%\0HTML格式
H?!`&?6Wk&d1W~D0<?phpPHPChina 开源社区门户#BM,w ?Ixq
include('Mail.php'
);PHPChina 开源社区门户I k}PP6bb#o p
include(
'Mail/mime.php'
);PHPChina 开源社区门户6KD?uMQ

r7zp6k0TI0
$text='This is a Christmas email from www.omni-batteies.com.'
;PHPChina 开源社区门户W%PF} en(Laz
$html='<html><body><h3><font color=red>This is a Christmas email from www.omni-batteies.com.</font></h3></body></html>'
;PHPChina 开源社区门户,M+lf6kb;a)x&b7V
$file='Special_Offer_For_Christmas.htm'
;PHPChina 开源社区门户"y,SB*C`(IL
$crlf="\n"
;PHPChina 开源社区门户K8G+iRp2M
$hdrs
= array(
/_ _3r WR ?}e&|W0              
'From'    =>'111@111.com'
,
e5q1g6V)d#?a"my0              
'To'      =>'Merry Christmas'
,PHPChina 开源社区门户g t#FDn5j P
              
'Subject'=>
'Christmas Message from www.omni-batteies.com'PHPChina 开源社区门户Yi3A$N5o^
              
);PHPChina 开源社区门户 bo\GGjy
PHPChina 开源社区门户 Z ij+Y/J2DwH
$mime= newMail_mime
();PHPChina 开源社区门户`A6_E6{6J5D
PHPChina 开源社区门户P8}vSo
$mime->setTXTBody($text
);PHPChina 开源社区门户1E\o b*Sf+o
$mime->setHTMLBody($file,true
);PHPChina 开源社区门户F:JMk t k
$mime->addAttachment($file,'text/html'
);
]x/G_Ed BCv0
/G8AU(B{l8muR2X#be0
$body=$mime->get
();
?|V]&rNnj c0
$hdrs=$mime->headers($hdrs
);PHPChina 开源社区门户&t[}]8IQ3f+L
$params['host'] ='mail.111.com'
;PHPChina 开源社区门户K{-G\u
$params['auth'] =true
;
@JV5B Do&{0
$params['username'] ='111@111.com'
;
uo-G8rm"[1?S Ti q0
$params['password'] ='111'
;
et\[ K0
$recipients= array('111@111.com','222@111.com'
);PHPChina 开源社区门户bA6Ik9f

h4F2v C)v"R'L0
$send= @$mail=&Mail::factory('smtp',$params
);PHPChina 开源社区门户9wYZOI7YH$\Z
$mail->send($recipients,$hdrs,$body
);PHPChina 开源社区门户$H(nbS"zr7S
if(
PEAR::isError($send
)) {
^Q)Vm.DuZ0    echo(
$send->getMessage
());PHPChina 开源社区门户Q \!to+}
} else {
{2e"um,is4Puun2S0    echo(
"send successfully"
);PHPChina 开源社区门户Q5n6s-h$]KC
}
|n[g z$o`0
show_source($_SERVER['PHP_SELF'
]);
*e(uoU4S?U0
?>
PHPChina 开源社区门户 e:rGa A/y/^'[(kXu


TAG: php

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 10309
  • 日志数: 51
  • 图片数: 3
  • 书签数: 3
  • 建立时间: 2007-02-07
  • 更新时间: 2008-02-27

RSS订阅

Open Toolbar