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。

  1. <?php
  2. require 'PHPMailerAutoload.php';
  3. $mail = new PHPMailer;
  4. $mail->SMTPDebug = 3; // Enable verbose debug output
  5. $mail->isSMTP(); // Set mailer to use SMTP
  6. $mail->Host = 'smtp.exmail.qq.com'; // Specify main and backup SMTP servers
  7. $mail->SMTPAuth = true; // Enable SMTP authentication
  8. $mail->Username = 'xxx@qq.com'; // SMTP username
  9. $mail->Password = 'yourpassword'; // SMTP password
  10. $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
  11. $mail->Port = 465; // TCP port to connect to
  12. $mail->setFrom('fromWho@qq.com', 'Mailer');
  13. $mail->addAddress('toWhom@qq.com', 'Ryan Miao'); // Add a recipient
  14. $mail->addAddress('ellen@example.com'); // Name is optional
  15. // $mail->addReplyTo('info@example.com', 'Information');
  16. $mail->addCC('cc@example.com');
  17. $mail->addBCC('bcc@example.com');
  18. $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  19. $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  20. $mail->isHTML(true); // Set email format to HTML
  21. $mail->Subject = 'Here is the subject';
  22. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  23. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  24. if(!$mail->send()) {
  25. echo 'Message could not be sent.';
  26. echo 'Mailer Error: ' . $mail->ErrorInfo;
  27. } else {
  28. echo 'Message has been sent';
  29. }

开启SMTPDebug可以查看日志

  1. `0` No output
  2. `1` Commands
  3. `2` Data and commands
  4. `3` As 2 plus connection status
  5. `4` Low-level data output

错误信息保存在 $mail->ErrorInfo对象中。

保存为mail.php, 命令行执行

  1. 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. zabbix server+agent+proxy搭建性能监控平台

    这是新找到了配置文件配置方法但未尝试 每个模块工作职责: Zabbix Server:负责接收agent发送的报告信息的核心组件,所有配置,统计数据及操作数据均由其组织进行: Database Sto ...

  2. C# int可以表示的最大值

    C#中int由4个字节组成,即由32个二进制数组成,由于最高位是用于表示正负数,所以实际上int所能表示的最大数为231-1=2147483647.

  3. Linux下apache支持PHP配置

    https://www.cnblogs.com/qiuxiao/p/6815350.html https://www.cnblogs.com/polestar/p/6086552.html

  4. POJ 3181 Dollar Dayz 【完全背包】

    题意: 给出两个数,n,m,问m以内的整数有多少种组成n的方法完全背包+大数划分 思路: dp[i][j] := 用i种价格配出金额j的方案数. 那么dp[i][0] = 1,使用任何价格配出金额0的 ...

  5. 【转载-译文】requests库连接池说明

    转译自:https://laike9m.com/blog/requests-secret-pool_connections-and-pool_maxsize,89/ Requests' secret: ...

  6. 配置CentOS6.5的yum源

    系统yum源(源,英文repository,就是资源库的意思:yum,全称Yellow dog Updater, Modified,是centos的软件包管理器.基于RPM包管理,能够从指定的服务器自 ...

  7. Mac配置Eclipse CDT的Debug出现的问题(转)

      问题1:出现 Could not determine GDB version using command: gdb --version 原因: mac上没有安装gdb或者gdb位置配置有问题 解决 ...

  8. 程序猿(媛)的葵花宝典-- 必备idea 插件plugins 提高编码效率

    最近发现了几个非常好用   提高编码效率 的idea 插件 跟大家分享一下,,,不用谢我!!!!!!!!!!!!! 因为idea自带的插件下载可能连接不上服务器而导致插件下载失败,所以这里推荐使用引入 ...

  9. MyBatis学习笔记3--使用XML配置SQL映射器

    <resultMap type="Student" id="StudentResult"> <id property="id&quo ...

  10. JSONObject基本内容(三)

    参考资料:http://swiftlet.net/archives/category/json    十分感谢!!!~~ 第三篇的内容,主要讲述的有两点: 1 .如何获取JSONObject中对应ke ...