WordPress配置邮件发送功能

方法一 适用私有云或自建服务器

WordPress自身的邮件发送功能需要调用服务器的sendmail组件

Linux CentOS安装:yum install sendmail

重启php-fpm进程 /etc/init.d/php-fpm restart

sendmail是否运行正常 /etc/init.d/sendmail status

/etc/init.d/sendmail start (启动sendmail)
/etc/init.d/sendmail stop (关闭sendmail)
/etc/init.d/sendmail restart (重启sendmail)

公有云(阿里、腾讯)要申请解封25端口,解封机率很低。

方法二:functions.php

//smtp发送邮件功能
add_action(‘phpmailer_init’, ‘mail_smtp’);
function mail_smtp( $phpmailer ) {
$phpmailer->FromName = ‘xxx’; //名字
$phpmailer->Host = ‘smtp.263.net’; //smtp地址,可以到你使用的邮件设置里面找
$phpmailer->Port = 465; //端口,一般不用修改
$phpmailer->Username = ‘xxx@rfls.edu.cn’; //邮件账号
$phpmailer->Password = ‘xxx’; //邮件密码
$phpmailer->From = ‘xxx@rfls.edu.cn’;//邮件账号
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = ‘ssl’; //tls or ssl (port=25留空,465为ssl)一般不用修改
$phpmailer->IsSMTP();
}

方法三:插件安装WP Mail SMTP by WPforms

附:

PHP邮件发送测试代码:

<?php
$txt = “hello”;
// 以下的邮箱地址改成你的
$mail = “xxx@xxx.cn”;
// 发送邮件
mail($mail, “My subject”, $txt);
echo “message was sent!”;
?>