1.首先是下载PHPMailer
http://code.google.com/a/apache-extras.org/p/phpmailer/
2.解压
从中取出class.phpmailer.php 和 class.smtp.php 放到你的项目的文件夹,因为我们等下会引用到它们.
3.创建发送邮件的函数,其中你需要配置smtp服务器
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 
 | function postmail($to,$subject = '',$body = ''){
 
 
 error_reporting(E_STRICT);
 date_default_timezone_set('Asia/Shanghai');
 require_once('class.phpmailer.php');
 include('class.smtp.php');
 $mail             = new PHPMailer();
 $body            = eregi_replace("[\]",'',$body);
 $mail->CharSet ="GBK";
 $mail->IsSMTP();
 $mail->SMTPDebug  = 1;
 
 
 $mail->SMTPAuth   = true;
 $mail->SMTPSecure = "ssl";
 $mail->Host       = 'stmp.163.com';
 $mail->Port       = 25;
 $mail->Username   = 'wangliang_198x';
 $mail->Password   = 'password';
 $mail->SetFrom('xxx@xxx.xxx', 'who');
 $mail->AddReplyTo('xxx@xxx.xxx','who');
 $mail->Subject    = $subject;
 $mail->AltBody    = 'To view the message, please use an HTML compatible email viewer!';
 $mail->MsgHTML($body);
 $address = $to;
 $mail->AddAddress($address, '');
 
 
 if(!$mail->Send()) {
 echo 'Mailer Error: ' . $mail->ErrorInfo;
 } else {
 
 }
 }
 
 | 
- 使用函数| 12
 
 | postmail('wangliang_198x@163.com','My subject','哗啦啦');
 
 |