wordpress使用phpmailer发送gmail邮件

  • 0.保证用于gmail账号已经开启imap服务,且你能正常访问到gmail的smtp服务。(需要climb over the wall)

  • 1.引入phpmailer相关类

原来在wp-includes里面有class-phpmailer.php和class-smtp.php两个文件,可以把它们拷贝到你需要编写发送邮件的那个文件的同级目录。然后引入代码如下:

include("class-phpmailer.php");
include("class-smtp.php");
  • 2.设置phpmailer配置
$mail = new PHPMailer();
$body = "Hi, my friend, just a test for audience! from ssr@interbrands.com";
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;

特别注意,要使用tls,而不是ssl。端口号为587,host为smtp.gmail.com。调试阶段可以设置SMTPDebug,否则应该删掉或者屏蔽这行的设置。

  • 3.设置发送内容
$mail->Username = "fightforphp@gmail.com";
$mail->Password = "xxxxxxx"; $body = "This is a test message not in awe of creation."; // 邮件内容
$mail->setFrom('fightforphp@mail.com', 'HelpForEmail');
$mail->Subject = 'Ask for help now'; // 邮件主题
$mail->msgHTML($body);
$mail->CharSet = "utf-8";
$address = "xxx@gmail.com";
$mail->addAddress($address);

关键不在于怎么用PHPMailer,关键在于当我们处于某种特定技术框架下怎么样写出具有good smell 和 particular的写法。

WordPress使用PHPMailer发送gmail邮件的更多相关文章

  1. 使用phpmailer发送smtp邮件时提示 SMTP Error: Could not authenticate 错误

    使用phpmailer发送smtp邮件时提示 SMTP Error: Could not authenticate 错误 这个错误是验证出现错误, $mail->Port = 25; //SMT ...

  2. 在Delphi中使用indy SMTP发送gmail邮件[转]

    在Delphi中使用indy SMTP发送gmail邮件[转] 2012-01-01 22:44:30|  分类: Delphi |  标签: |举报 |字号大中小 订阅     在Delphi中发送 ...

  3. WordPress用户注册无法发送密码邮件怎么回事?

    wordpress无法发送电子邮件.可能原因:您的主机禁用了 mail() 函数 等等几句话.在网上一搜,很快找到了解决方案:使用wp-mail-smtp插件. 一.插件下载安装.可以在wordpre ...

  4. 在命令行上 Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件

    在命令行写email from ubuntu 参考:      http://www.habadog.com/2011/11/23/send-mail-with-msmtp-mutt-linux    ...

  5. Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件

    参考:        http://www.cnblogs.com/refrag/archive/2012/11/28/2793533.html         http://www.habadog. ...

  6. ThinkPHP使用PHPmailer发送Email邮件

    下面介绍thinkphp如何使用phpmailer发送邮件,使用这个邮件发送类,配置好参数后,一句话即可发送邮件.仅适合于thinkphp框架. 第一步,下载类库 将Mail.class.php复制到 ...

  7. Ubuntu下配置用msmtp发送gmail邮件

    从https://gist.github.com/JosefJezek/6194563上找到的一个配置脚本,下载后添加可执行权限,然后运行即可. 下面是脚本setup-msmtp-for-gmail. ...

  8. PHPmailer群发Gmail的常见问题

    博主小白一枚,phpmailer只会一些基本的用法,就这样一个邮件的群发功能也难住了我一周,下面把我遇到的问题给大家总结一下 1.Could not authenticate 首先,如果你没有使用循环 ...

  9. C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...

随机推荐

  1. fatal: Not a git repository (or any of the parent directories)

    当从github.com上面下载下了Firmware后,无意中删除了Firmware目录下的.git文件夹,再去编译就会出现:   fatal: Not a git repository (or an ...

  2. multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded

    情景再现: 上传文件到.net(wcf)后台时,总是上传不成功,后台要求Content-Type是application/octet-stream,我使用multipart/form-data方式,c ...

  3. asp dotnet core 通过图片统计 csdn 用户访问

    在 csdn 的访问统计里面,只能用 csdn 提供的访问统计,因为在 csdn 中不支持在博客加上 js 代码,也就是无法使用友盟等工具统计. 通过在 asp dotnet core 创建一个图片链 ...

  4. Jenkins 配置自动合并 release 分支到 master 分支

    本文告诉大家如何在 Jenkins 配置合并到 release 的内容自动合并到 gitlab 的 master 分支 首先需要两个仓库,一个是 gitlab 的仓库,另一个是 Jenkins 的仓库 ...

  5. 使用git命令修改commit提交信息

    很多时候我们在提交代码时可能会把commit提交信息写错了,这个时候我们就可以用到下面的git命令来修改commit提交信息 git commit --amend 输入"i"之后进 ...

  6. 一个简单的Web服务器-支持Servlet请求

    上接 一个简单的Web服务器-支持静态资源请求,这个服务器可以处理静态资源的请求,那么如何处理Servlet请求的呢? 判断是否是Servlet请求 首先Web服务器需要判断当前请求是否是Servle ...

  7. 2018-2-13-C#-动态加载卸载-DLL

    title author date CreateTime categories C# 动态加载卸载 DLL lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...

  8. 2018-2-13-win10-UWP-九幽数据分析

    title author date CreateTime categories win10 UWP 九幽数据分析 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 1 ...

  9. 运行APP脚本的步骤

    1.打开ride(可运行命令:ride.py) 2.启动Appium 3.启动android-sdk\tools\uiantomatorviewer.bat(目的是为了抓取设备元素ID)

  10. F#周报2019年第51&52期

    新闻 介绍DataFrame 介绍System.Threading.Channels ConfigureAwait常见问题 第三次年度C#降临节 .NET会议--2020年1月14日 如何找到F#的工 ...