wp邮件服务器怎么设置,【纯代码】wordpress设置发送邮件方法

很多服务器不支持mail函数,无法实现发送邮件功能,网上有很多smtp邮件功能的插件,但今天提供的方法是如何修改wordpress代码实现smtp邮件功能,首先就是要开启你的邮箱的smtp服务,这里就不做介绍了。

方法:找到相应主题下的functions.php(默认路径为wp-content/themes/主题名/fuinctions.php),

使用php编辑器编辑fuinctions.php,在fuinctions.php文件中增加一相应函数如下:

//使用 smtp 发邮件

add_action('phpmailer_init', 'fanly_mail_smtp');

function fanly_mail_smtp( $phpmailer ) {

$phpmailer->IsSMTP();

$phpmailer->SMTPAuth = true;//启用 SMTPAuth 服务

$phpmailer->Port = 465;//MTP 邮件发送端口,这个和下面的 SSL 验证对应,如果这里填写 25,则下面参数为空

$phpmailer->SMTPSecure ="ssl";//是否验证 ssl,与 MTP 邮件发送端口对应,如果不填写,则上面的端口须为 25

$phpmailer->Host = "smtp.qq.com";//邮箱的 SMTP 服务器地址,目前 smtp.exmail.qq.com 为 QQ 邮箱和腾讯企业邮箱 SMTP

$phpmailer->Username = "88888@qq.com";//你的邮箱地址

$phpmailer->Password ="xxxxx";//你的邮箱发送邮件授权码

}

//发件地址记得和 smtp 邮箱一致即可

function fanly_wp_mail_from() {

return '2157587@qq.com';}

add_filter( 'wp_mail_from', 'fanly_wp_mail_from' );

add_action('publish_post', 'refresh_front_page', 0); //发布或者更新日志时候刷新首页

add_action('delete_post', 'refresh_front_page', 0); //删除日志时候刷新首页

function refresh_front_page(){

$front_page_id = get_option('page_on_front'); //获取显示首页的页面 ID

wp_cache_post_edit($front_page_id); //刷新该页

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值