PHP5.3版本, 采用PHPMailer 使用SMTP发送邮件(针对低版本PHP发送邮件)

17 篇文章 0 订阅

PHPMailer 发送邮件

如果你的PHP版本是5.5以上, 请查看 https://blog.csdn.net/yule117737767/article/details/98599314

本篇内容支持PHP 5.0 - 7.0版本发送邮件. 

首先下载PHPMailer 5.2版本分支, https://github.com/PHPMailer/PHPMailer/tree/5.2-stable

PHPMailer 需要开启 socket 和 openssl 扩展, 不会开启的请查看上一篇文章

 依然使用SMTP来发送邮件, 使用smtp.qq.com, 具体开启操作查看上一篇文章

 


下载的PHPMailer 为5.2版, 需要PHP5.3版本以上

里面有一个examples例子, 这里面例子非常齐全 .主页是: ./PHPMailer-5.2-stable/examples/index.html

里面包含各种例子, 最后浏览器带翻译插件, 直接在浏览器翻译成中文

 每一个里面都有实例. 可以自己研究, 最简单的就是 查看smtp.phps,

From_Name
名称
From_Email
电子邮件地址
To_Name
收件人姓名
To_Email
收件人电子邮件地址
CC
抄送
BCC 密抄送
Message /Subject内容 / 标题
Test Type邮件类型 SMTP
SMTP Debug启用SMTP调试 0,不显示 1,客户端 2,客户端和服务器
SMTP Server

设置邮件服务器 

SMTP PortSMTP端口号
SMTP Security设置登录鉴权 SSL
SMTP Authenticate是否使用SMTP身份验证, 1,0
Authenticate UsernameSMTP身份验证的账号
Authenticate PasswordSMTP身份验证的密码

 

SMTP发送邮件例子

date_default_timezone_set('Etc/UTC');

require '../PHPMailerAutoload.php';//引入加载

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.qq.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
// 设置使用ssl加密方式登录鉴权
$mail->SMTPSecure = 'ssl';
//Username to use for SMTP authentication
$mail->Username = "1177@qq.com";
//Password to use for SMTP authentication
$mail->Password = "qqclxpjpuyjhbjdg";
//Set who the message is to be sent from
$mail->setFrom('1177@qq.com', 'admin');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last2');
//Set who the message is to be sent to
$mail->addAddress('376064028@qq.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';//标题
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));//内容
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');//附件

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

这个版本的PHPMailer 存在发送中文部分邮箱不兼容问题.  我同时发送给2个邮箱, qq邮箱显示中文正常,而另一个公司邮箱显示乱码, 网上找的方式试过, 都无效, 如有解决方法的, 可以留个言,

其它的跟.6.6版本没区别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值