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发送邮件的更多相关文章

  1. 基于php5.6 php.ini详解

    PHP中auto_prepend_file与auto_append_file的用法 第一种方法:在所有页面的顶部与底部都加入require语句.例如:?123require('header.php') ...

  2. linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co

    https://zhidao.baidu.com/question/509191264.html?fr=iks&word=PHPMailerSMTP+connect()+failed& ...

  3. PHP (sendmail / PHPMailer / ezcMailComposer)发送邮件

    一. 使用 PHP 内置的 mail() 函数 1. Windows 下 环境:WampServer2.5(Windows 10,Apache 2.4.9,MySQL 5.6.17,PHP 5.5.1 ...

  4. php使用PHPMailer邮件类发送邮件

    PHPMailer是一个用于发送电子邮件的PHP函数包.它提供的功能包括:*.在发送邮时指定多个收件人,抄送地址,暗送地址和回复地址*.支持多种邮件编码包括:8bit,base64,binary和qu ...

  5. 基于nodemailer使用阿里云企业邮箱发送邮件(526错误的解决)

    在虽然日常生活中,QQ,微信等即时聊天工具几乎主导了人们的生活,但是邮件依然是现代生活不可缺少的一部分.这篇文章主要讲述使用node.js 中的nodemail模块操作阿里云的企业邮箱发送邮件 (52 ...

  6. 记一次邮件推送的坑,c#基于smtp使用腾讯企业邮箱发送邮件总是失败的原因

    今天在弄企业邮箱推送的东西,原版代码是这样的 public void SendEmail(string title, string content) { try { MailMessage mailM ...

  7. PHPmailer发送邮件时的常见问题及解决办法

    来源:http://www.chinastor.com/a/jishu/mailserver/0G392262014.html 使用PHPmailer发送邮件时的常见问题总结: 一,没有定义发送邮箱$ ...

  8. 使用 PHPMailer 发送邮件出现诡异bug,间歇性发送失败

    场景 使用PHPMailer的SMTP发送邮件,用的是腾讯企业邮箱 smtp.exmail.qq.com 在邮箱设置里看到配置smtp方法 问题描述 本地windows开发环境发送邮件100%成功 远 ...

  9. phpQuery—基于jQuery的PHP实现

    转载于:http://www.cnblogs.com/in-loading/archive/2012/04/11/2442697.html Query的选择器之强大是有目共睹的,phpQuery 让p ...

随机推荐

  1. 关于java中Stream理解

    关于java中Stream理解 Stream是什么 Stream:Java 8新增的接口,Stream可以认为是一个高级版本的Iterator.它代表着数据流,流中的数据元素的数量可以是有限的, 也可 ...

  2. samba 设置文件的读写权限

    原文:https://blog.csdn.net/lan120576664/article/details/50396511 打开配置文件 sudo pico /etc/samba/smb.conf ...

  3. PHP替换指定字符串

    在PHP中,有两个函数可以实现字符串替换,strtr()和str_repalce()函数. 首先我们简单了解下strtr()函数的定义及语法. strtr:转换指定字符. 两个语法: 第一种语法: s ...

  4. poj1179 环形+区间dp

    因为要用到模,所以左起点设置为0比较好 #include<iostream> #include<cstdio> #include<cstring> #define ...

  5. nginx部署网站

    部署单个网站非常简单,只要将网站HTML文件和资源文件(.jpg .css .js等)全部复制到nginx-1.13.12\html目录下. 然后启动 启动进入cmd,切换到nginx-1.13.12 ...

  6. thinkphp验证码的使用

    thinkphp不仅封装了验证规则 还封装了验证码 文件的位置是ThinkPHP\Library\Think\Verify.class.php 下面简单的说一下如何使用 我们现在控制器里新建一个方法 ...

  7. zjoi2017 仙人掌

    题解: 好难的dp啊...看题解看了好久才看懂 http://blog.csdn.net/akak__ii/article/details/65935711 如果一开始的图就不是仙人掌,答案显然为0, ...

  8. Codeforces 679C Bear and Square Grid

    Bear and Square Grid 枚举k * k 的位置, 然后接上它周围白色连通块的数量, 再统计完全在k * k范围里的连通块, 这个只要某个连通块全部的方格 在k * k里面就好, 并且 ...

  9. BZOJ1180 [CROATIAN2009]OTOCI LCT

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1180 本题和BZOJ2843一样. BZOJ2843 极地旅行社 LCT 题意概括 有n座岛 每座 ...

  10. 第七章|7.4并发编程| I/O模型

    I/O模型 协程是单线程下的并发,并不是对性能都有所提升,一定是监测单个线程下的多个任务的I/O,遇到I/O不要让它阻塞,给它自动切换到其他任务去,这样就能提高单个线程下的运行效率.--->&g ...