免插件为wordpress配置SMTP服务
- 时间:2020-05-16 19:39:54
- 分类:网络文摘
- 阅读:140 次
由于很多 wordpress 主机禁用了 mail 函数,所以不支持邮件发送,造成用户注册或找回密码时无法收到验证邮件。此问题可通过第三方邮件服务器 SMTP 方式代替 wordpress 默认 mail() 函数来解决。网上介绍的方法大多是通过插件配置 wordpress 的 SMTP ,本文介绍的方法是通过代码来实现。具体操作如下:
将如下代码添加到当前 wordpress主题函数模板 functions.php 文件中,并修改相关信息后保存。
- // 配置邮件STMP
- add_action('phpmailer_init', 'mail_smtp');
- function mail_smtp( $phpmailer ) {
- $phpmailer->FromName = '骤雨打新荷'; // 发件人昵称
- $phpmailer->Host = 'smtp.qq.com'; // 邮箱SMTP服务器
- $phpmailer->Port = 465; // SMTP端口,不需要改
- $phpmailer->Username = '[email protected]'; // 邮箱账户
- $phpmailer->Password = '112211221122'; // 此处填写邮箱生成的授权码,不是邮箱登录密码
- $phpmailer->From = '[email protected]'; // 邮箱账户同上
- $phpmailer->SMTPAuth = true;
- $phpmailer->SMTPSecure = 'ssl'; // 端口25时 留空,465时 ssl,不需要改
- $phpmailer->IsSMTP();
- }
说明:发件邮箱不是QQ邮箱或126邮箱的,不需要授权码,请在代码第8行 $phpmailer->Password 配置中填写邮箱登录密码。
下面以QQ邮箱为例,简单介绍一下开启IMAP/SMTP服务和获得第三方授权码的方法。
一、开启IMAP/SMTP服务。
登录你的QQ邮箱,依次点击,设置 → 账户,找到“POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务”设置选项,开启邮箱“IMAP/SMTP服务”,开启时需要手机发送短信验证。
二、获取第三方授权码
点击下面的“生成授权码 ”,按要求发送短信:“配置邮件客户端”到指定的号码,之后点击“我已发送”,会自动生一个授权码,请记好这个授权码,因为只显示一次,没记住只能再次发送短信了,将这个授权码填写到上面的代码配置信息中即可。
注:下图是QQ邮箱和网易邮箱的IMAP/SMTP信息,貌似目前所有邮箱端口都可以设置为 465 并支持 ssl 加密。

如果用户注册时点击邮件中的验证链接失效请参考:解决wordpress密码设置链接失效的问题
推荐阅读:Breadth-First Search Algorithm to Solve Puzzle (Rotting Oranges) Facebook Onsite Interview Preparation Part 1: Motivation/Bahavio Celebrate WordPress’ 13th Birthday With These Interesting Facts 5 Ways to Use Your Smartphone to Build a Better Blog The Most Expensive Domain Sales Ever 15 Ways Of How Not To Kill Your Leadership Authority Study Shows Strong Growth of Tech Inventions to Fight Climate Ch Interested in Bitcoins? Here are 10 Blogs You Need to Check Out Your Blog’s Been Hacked! Here’s What You Need to Do #DiningForBrussels: How Belgium Is Fighting Terrorism With A For
- 评论列表
-
- 添加评论