PHP程序员站--PHP编程开发平台
 当前位置:主页 >> PHP基础 >> 基础文章 >> 

PHPMailer邮件类的使用教程

PHPMailer邮件类的使用教程

来源:互联网  作者:网络转载  发布时间:2008-01-14
PHPMailer邮件类的使用教程 转载请保留作者内容: http://www.cgsir.com 第一步:
转载请保留作者内容: http://www.cgsir.com
第一步:需要下载PHPMailer文件包phpmailer-1.73.tar.gz   来自开源社区: http://phpmailer.sourceforge.net/
第二步:确认你的服务器系统已经支持socket 如下图,通过phpinfo();查看是否支持sockets



  如果没有这一项就请注意: socket 是属于PHP扩展部分,编译时必须给定一个用于./configure --enable-sockets  的配置选项。


第三步:把文件解压到你的web服务器目录下,调用类就可以了,说明:首先包含 class.phpmailer.php,然后创建对象,设置参数,调用成员函数。具体请见下面的示例代码:

以下为引用的内容:

<?php
/*******************************
* 作者:李英江
* 日期:2006-12-7
*******************************/

require("phpmailer/class.phpmailer.php");
function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
$mail = new PHPMailer();
$mail->IsSMTP();
// send via SMTP

$mail->Host = "200.162.244.66";
// SMTP servers

$mail->SMTPAuth = true;
// turn on SMTP authentication

$mail->Username = "yourmail";
// SMTP username 注意:普通邮件认证不需要加 @域名



$mail->Password = "mailPassword";
// SMTP password

$mail->From = "yourmail@cgsir.com";
// 发件人邮箱

$mail->FromName = "cgsir.com管理员";
// 发件人


$mail->CharSet = "GB2312";
// 这里指定字符集!

$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username");
// 收件人邮箱和姓名

$mail->AddReplyTo("yourmail@cgsir.com","cgsir.com");
//$mail->WordWrap = 50; // set word wrap

//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment

//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true);
// send as HTML


        
// 邮件主题

$mail->Subject = $subject;
// 邮件内容

$mail->Body =
'
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
        欢迎来到<a href="http://www.cgsir.com">http://www.cgsir.com</a> <br /><br />
感谢您注册为本站会员!<br /><br />
</body>
</html>
'
;
$mail->AltBody ="text/html";
if(!$mail->Send())
{
  echo "邮件发送有误 <p>";
  echo "邮件错误信息: " . $mail->ErrorInfo;
  exit;
}
else {
  echo "$user_name 邮件发送成功!<br />";
}
}

// 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)

smtp_mail('yourmail@cgsir.com', '欢迎来到cgsir.com!', 'NULL', 'cgsir.com', 'username');
?>


要注意的内容:
  1. 邮件的字符集设置, $mail->CharSet = "GB2312";            // 这里指定字符集!在这里我只指定为GB2312因为这样Outlook能正常显示邮件主题,我尝试过设为utf-8但在Outlook下显示乱码。
  2. 如果是发送html格式的邮件,那么记得也指定<meta ... charset=GB2312">
  3. 如果你想用它来群发邮件的话,记得修改包含文件函数,如:
  require("phpmailer/class.phpmailer.php");
  改为
  require_once("phpmailer/class.phpmailer.php");
  否则的话会产生类的重定义。

本文只做到抛砖引玉的作用,真正的使用还是靠大家耐心去摸索。如果您发现本文有错误之处,请来信告知:我的邮箱是admin@cgsir.com ,谢谢! 

 

官方说明文档:
http://phpmailer.sourceforge.net/

Here's a complex example of sending an HTML email with SMTP authentication and attachments

以下为引用的内容:
require("class.phpmailer.php");$mail = new PHPMailer();$mail->IsSMTP();    


下在地址
/html/yuanmagongxiang/PHP_Class/20080114/666.html

延伸阅读:
phpmailer发送Email类
PHPMailer安装及简单实例
phpmailer所有对象和属性 中文
如何用php结合phpmailer发送邮件
Tags:   邮件类   phpmailer   phpmailer     教程   邮件   Mail   SMTP   gb2312   php   使用  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号