Home > php教程 > php手册 > body text

PHPMailer邮件类利用smtp.163.com发送邮件方法

WBOY
Release: 2016-06-13 12:27:08
Original
2869 people have browsed it

第一步:需要下载PHPMailer文件包phpmailer-1.73.tar.gz 来自开源社区: http://phpmailer.sourceforge.net/
第二步:确认你的服务器系统已经支持socket 如下图,通过phpinfo();查看是否支持sockets
  如果没有这一项就请注意: socket 是属于PHP扩展部分,编译时必须给定一个用于./configure --enable-sockets 的配置选项。

第三步:把文件解压到你的web服务器目录下,调用类就可以了,说明:首先包含 class.phpmailer.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 = '





娆㈣
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template