您好,欢迎访问一九零五行业门户网

利用PHPMailer 来完成PHP的邮件发送 #转载自:大菜鸟在云端#

利用phpmailer 来完成php的邮件发送
1.首先是下载phpmailer
http://code.google.com/a/apache-extras.org/p/phpmailer/
2.解压
从中取出class.phpmailer.php 和 class.smtp.php 放到你的项目的文件夹,因为我们等下会引用到它们.
3.创建发送邮件的函数,其中你需要配置smtp服务器
function postmail($to,$subject = '',$body = ''){ //author:jiucool website: http://www.jiucool.com //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文 //error_reporting(e_all); error_reporting(e_strict); date_default_timezone_set('asia/shanghai');//设定时区东八区 require_once('class.phpmailer.php'); include('class.smtp.php'); $mail = new phpmailer(); //new一个phpmailer对象出来 $body = eregi_replace([\],'',$body); //对邮件内容进行必要的过滤 $mail->charset =gbk;//设定邮件编码,默认iso-8859-1,如果发中文此项必须设置,否则乱码 $mail->issmtp(); // 设定使用smtp服务 $mail->smtpdebug = 1; // 启用smtp调试功能 // 1 = errors and messages // 2 = messages only $mail->smtpauth = true; // 启用 smtp 验证功能 $mail->smtpsecure = ssl; // 安全协议,可以注释掉 $mail->host = 'stmp.163.com'; // smtp 服务器 $mail->port = 25; // smtp服务器的端口号 $mail->username = 'wangliang_198x'; // smtp服务器用户名,ps:我乱打的 $mail->password = 'password'; // smtp服务器密码 $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!'; // optional, comment out and test $mail->msghtml($body); $address = $to; $mail->addaddress($address, ''); //$mail->addattachment(images/phpmailer.gif); // attachment //$mail->addattachment(images/phpmailer_mini.gif); // attachment if(!$mail->send()) { echo 'mailer error: ' . $mail->errorinfo; } else {// echo message sent!恭喜,邮件发送成功!; }}

4. 使用函数
postmail('wangliang_198x@163.com','my subject','哗啦啦');

1.首先是下载phpmailer
http://code.google.com/a/apache-extras.org/p/phpmailer/
2.解压
从中取出class.phpmailer.php 和 class.smtp.php 放到你的项目的文件夹,因为我们等下会引用到它们.
3.创建发送邮件的函数,其中你需要配置smtp服务器
function postmail($to,$subject = '',$body = ''){ //author:jiucool website: http://www.jiucool.com //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文 //error_reporting(e_all); error_reporting(e_strict); date_default_timezone_set('asia/shanghai');//设定时区东八区 require_once('class.phpmailer.php'); include('class.smtp.php'); $mail = new phpmailer(); //new一个phpmailer对象出来 $body = eregi_replace([\],'',$body); //对邮件内容进行必要的过滤 $mail->charset =gbk;//设定邮件编码,默认iso-8859-1,如果发中文此项必须设置,否则乱码 $mail->issmtp(); // 设定使用smtp服务 $mail->smtpdebug = 1; // 启用smtp调试功能 // 1 = errors and messages // 2 = messages only $mail->smtpauth = true; // 启用 smtp 验证功能 $mail->smtpsecure = ssl; // 安全协议,可以注释掉 $mail->host = 'stmp.163.com'; // smtp 服务器 $mail->port = 25; // smtp服务器的端口号 $mail->username = 'wangliang_198x'; // smtp服务器用户名,ps:我乱打的 $mail->password = 'password'; // smtp服务器密码 $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!'; // optional, comment out and test $mail->msghtml($body); $address = $to; $mail->addaddress($address, ''); //$mail->addattachment(images/phpmailer.gif); // attachment //$mail->addattachment(images/phpmailer_mini.gif); // attachment if(!$mail->send()) { echo 'mailer error: ' . $mail->errorinfo; } else {// echo message sent!恭喜,邮件发送成功!; }}

4. 使用函数
postmail('wangliang_198x@163.com','my subject','哗啦啦');

其它类似信息

推荐信息