基于php5.5使用PHPMailer-5.2发送邮件
PHPMailer - A full-featured email creation and transfer class for PHP。
在PHP环境中可以使用PHPMailer来创建和发送邮件。
最新版本(20181012)是PHPMailer 6.0.5,这个无法兼容php5.5以下的环境。由于我需要维护
php5.3的项目,需要切换到PHPMailer5.2来发送邮件。
下载地址: https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.24
基本使用
下载解压后。新建一个测试demo。
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.exmail.qq.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx@qq.com'; // SMTP username
$mail->Password = 'yourpassword'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('fromWho@qq.com', 'Mailer');
$mail->addAddress('toWhom@qq.com', 'Ryan Miao'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
开启SMTPDebug可以查看日志
`0` No output
`1` Commands
`2` Data and commands
`3` As 2 plus connection status
`4` Low-level data output
错误信息保存在 $mail->ErrorInfo
对象中。
保存为mail.php, 命令行执行
php mail.php
即可看到日志,以及邮件发送成功。
基于php5.5使用PHPMailer-5.2发送邮件的更多相关文章
- 基于php5.6 php.ini详解
PHP中auto_prepend_file与auto_append_file的用法 第一种方法:在所有页面的顶部与底部都加入require语句.例如:?123require('header.php') ...
- linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co
https://zhidao.baidu.com/question/509191264.html?fr=iks&word=PHPMailerSMTP+connect()+failed& ...
- PHP (sendmail / PHPMailer / ezcMailComposer)发送邮件
一. 使用 PHP 内置的 mail() 函数 1. Windows 下 环境:WampServer2.5(Windows 10,Apache 2.4.9,MySQL 5.6.17,PHP 5.5.1 ...
- php使用PHPMailer邮件类发送邮件
PHPMailer是一个用于发送电子邮件的PHP函数包.它提供的功能包括:*.在发送邮时指定多个收件人,抄送地址,暗送地址和回复地址*.支持多种邮件编码包括:8bit,base64,binary和qu ...
- 基于nodemailer使用阿里云企业邮箱发送邮件(526错误的解决)
在虽然日常生活中,QQ,微信等即时聊天工具几乎主导了人们的生活,但是邮件依然是现代生活不可缺少的一部分.这篇文章主要讲述使用node.js 中的nodemail模块操作阿里云的企业邮箱发送邮件 (52 ...
- 记一次邮件推送的坑,c#基于smtp使用腾讯企业邮箱发送邮件总是失败的原因
今天在弄企业邮箱推送的东西,原版代码是这样的 public void SendEmail(string title, string content) { try { MailMessage mailM ...
- PHPmailer发送邮件时的常见问题及解决办法
来源:http://www.chinastor.com/a/jishu/mailserver/0G392262014.html 使用PHPmailer发送邮件时的常见问题总结: 一,没有定义发送邮箱$ ...
- 使用 PHPMailer 发送邮件出现诡异bug,间歇性发送失败
场景 使用PHPMailer的SMTP发送邮件,用的是腾讯企业邮箱 smtp.exmail.qq.com 在邮箱设置里看到配置smtp方法 问题描述 本地windows开发环境发送邮件100%成功 远 ...
- phpQuery—基于jQuery的PHP实现
转载于:http://www.cnblogs.com/in-loading/archive/2012/04/11/2442697.html Query的选择器之强大是有目共睹的,phpQuery 让p ...
随机推荐
- zabbix server+agent+proxy搭建性能监控平台
这是新找到了配置文件配置方法但未尝试 每个模块工作职责: Zabbix Server:负责接收agent发送的报告信息的核心组件,所有配置,统计数据及操作数据均由其组织进行: Database Sto ...
- C# int可以表示的最大值
C#中int由4个字节组成,即由32个二进制数组成,由于最高位是用于表示正负数,所以实际上int所能表示的最大数为231-1=2147483647.
- Linux下apache支持PHP配置
https://www.cnblogs.com/qiuxiao/p/6815350.html https://www.cnblogs.com/polestar/p/6086552.html
- POJ 3181 Dollar Dayz 【完全背包】
题意: 给出两个数,n,m,问m以内的整数有多少种组成n的方法完全背包+大数划分 思路: dp[i][j] := 用i种价格配出金额j的方案数. 那么dp[i][0] = 1,使用任何价格配出金额0的 ...
- 【转载-译文】requests库连接池说明
转译自:https://laike9m.com/blog/requests-secret-pool_connections-and-pool_maxsize,89/ Requests' secret: ...
- 配置CentOS6.5的yum源
系统yum源(源,英文repository,就是资源库的意思:yum,全称Yellow dog Updater, Modified,是centos的软件包管理器.基于RPM包管理,能够从指定的服务器自 ...
- Mac配置Eclipse CDT的Debug出现的问题(转)
问题1:出现 Could not determine GDB version using command: gdb --version 原因: mac上没有安装gdb或者gdb位置配置有问题 解决 ...
- 程序猿(媛)的葵花宝典-- 必备idea 插件plugins 提高编码效率
最近发现了几个非常好用 提高编码效率 的idea 插件 跟大家分享一下,,,不用谢我!!!!!!!!!!!!! 因为idea自带的插件下载可能连接不上服务器而导致插件下载失败,所以这里推荐使用引入 ...
- MyBatis学习笔记3--使用XML配置SQL映射器
<resultMap type="Student" id="StudentResult"> <id property="id&quo ...
- JSONObject基本内容(三)
参考资料:http://swiftlet.net/archives/category/json 十分感谢!!!~~ 第三篇的内容,主要讲述的有两点: 1 .如何获取JSONObject中对应ke ...