PHP发送邮件类库PHPMailer的简单使用
来源:互联网 发布:最新犀牛软件下载 编辑:程序博客网 时间:2024/04/30 17:16
最近需要用到发送邮件的功能,原本是用PHP自带的mail()函数发送的。php mail()这个方法非常简单、方便、易用,但是除了网易邮箱、QQ邮箱、GMAIL邮箱等常用的邮箱可以收到之外,经测试HOTMAIL、TOM、LIVE等邮箱是收不到此类邮件的。所以就转而使用PHPMailer这个强大的邮件发送类。
使用官方自带的一些例子,有些会报 Mailer Error: Could not instantiate mail function. 这个错误。参考了一些资料之后,还是自己写了一个方法。代码很简单,就不多解释了。
01
function
mailto(
$nickname
,
$address
,
$id
,
$activation_code
)
02
{
03
date_default_timezone_set(
'PRC'
);
04
include_once
(
"class.phpmailer.php"
);
05
06
$mail
=
new
PHPMailer();
// defaults to using php "mail()"
07
$mail
->IsSMTP();
08
$mail
->Host =
"smtp.163.com"
;
// SMTP 服务器
09
$mail
->SMTPAuth = true;
// 打开SMTP 认证
10
$mail
->Username =
"nowamagic@163.com"
;
// 用户名
11
$mail
->Password =
"yourpassword"
;
// 密码
12
13
//$body = file_get_contents('application/views/nmra/register.html');
14
//$body = preg_replace('/\\\\/','', $body); //Strip backslashes
15
$body
=
'<p><body style="margin: 10px;"></p>'
;
16
$body
.=
'<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; ">'
;
17
$body
.=
'<div align="center"><img src="images/phpmailer.gif" style="height: 90px; width: 340px"></div>'
;
18
$body
.=
'<p>'
.
$nickname
.
',您好。</p>'
;
19
$body
.=
'<p>恭喜你成为简明现代魔法研究协会的第'
.
$id
.
'名会员。</p>'
;
20
$body
.=
'<p>现代魔法研究协会(NowaMagic Research Association)是一个程序猿、攻城狮、设计狮和开发者们技术交流、话题讨论的社区。希望在这里你能找到感兴趣的话题与志同道合的朋友。</p>'
;
21
$body
.=
'请点击以下链接验证您的邮箱,请注意域名为nowamagic.net:<a href="http://www.nowamagic.net/librarys/accounts/activation/?code="'
.
$activation_code
.
'" target="_blank">http://www.nowamagic.net/librarys/accounts/activation/?code='
.
$activation_code
.
'</a>'
;
22
$body
.=
'<p>顺祝工作学习愉快,生活舒心。</p>'
;
23
$body
.=
'</div></body>'
;
24
//echo $body;
25
26
$mail
->AddReplyTo(
"nowamagic@163.com"
,
"Gonn"
);
27
$mail
->SetFrom(
'nowamagic@163.com'
,
'Gonn'
);
28
$mail
->AddReplyTo(
"nowamagic@163.com"
,
"Gonn"
);
29
$address
=
"252211974@qq.com"
;
30
//$address = "nowamagic@gmail.com";
31
$mail
->AddAddress(
$address
,
$nickname
);
32
33
$subject
=
"收到来自简明现代魔法的邮件"
;
34
$mail
->Subject =
"=?UTF-8?B?"
.
base64_encode
(
$subject
).
"?="
;
35
// optional, comment out and test
36
$mail
->AltBody =
"To view the message, please use an HTML compatible email viewer!"
;
37
$mail
->MsgHTML(
$body
);
38
39
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
40
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
41
42
if
(!
$mail
->Send()) {
43
//echo "Mailer Error: " . $mail->ErrorInfo;
44
}
45
else
{
46
//echo "Message sent!";
47
}
48
}
使用的时候只要引入两个PHP类,然后自己写个方法就OK了,两个类很小,发送邮件速度也很快。
PHPMailer 是一个功能强大的邮件类,其主要功能特点:
- 支持邮件 s/mime加密的数字签名
- 支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
- 可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
- 支持文本/HTML格式邮件
- 可以嵌入image图像
- 对于邮件客户端不支持HTML阅读的进行支持
- 功能强大的发送邮件调试功能debug
- 自定义邮件header
- 冗余SMTP服务器支持
- 支持8bit, base64, binary, and quoted-printable 编码
- 文字自动换行
- 支持多附件发送功能
- 支持SMTP服务器验证功能
- 在Sendmail, qmail, Postfix, Gmail, Imail, Exchange 等平台测试成功
- 提供的下载文件中,包括内容详细的说明文档及示例说明,所以不用担心难于上手的问题!
- PHPMailer 非常小巧、简单、方便、快捷
本文地址:http://www.nowamagic.net/librarys/veda/detail/1944,欢迎访问原出处。
- PHP发送邮件类库PHPMailer的简单使用
- PHP发送邮件类库PHPMailer的简单使用
- PHP使用PHPMailer类发送邮件
- PHPMailer的使用--邮件发送
- 关于PHP 发送SMTP邮件 的邮件类phpmailer 参数
- PHPMailer IIS下的PHP脚本使用GMAIL发送邮件
- PHP发送邮件---phpmailer
- 【PHP邮件发送】PHPMailer
- php邮件发送-phpmailer
- PHP发送邮件(PHPMailer)
- Web_PHP_使用PHPMailer类实现PHP邮件发送功能;
- PHP使用PHPmailer发送邮件方法
- 使用phpmailer.php进行邮件发送
- php 使用composer phpmailer发送qq邮件
- 使用PHPMailer发送邮件
- 使用 PHPMailer 发送邮件
- 使用phpMailer发送邮件
- 使用PHPMailer发送邮件
- 黑马程序员_File详解
- PHP多种序列化/反序列化的方法
- jQuery 1.42 中文手册
- my.cnf for MySQL 5.5 on Linux 2.6.32
- 让PHP代码优雅起来的一些编程习惯
- PHP发送邮件类库PHPMailer的简单使用
- WEB开发监控在线用户
- Swust 485 自守数 / Poj 2205 Self-Replicating Numbers
- 三维CAD软件项目即将验收 3D打印获突破
- wiki
- 深入php内核一(概述)
- C++结构体复制的相关问题
- 设计沟通的七条经验
- 深入php内核二(可扩展性)