WordPress限制邮箱每天的发送数量

wordpress邮箱发送邮件基本是靠用户设置smtp发送的,使用主机发送信息有可能被用户邮箱识别为垃圾邮件;现在的企业邮箱大部分是有发件条数限制得到,如果在超额后继续发送的话则会扣费,直至欠费。这时候则需要限制每日发送的条数。

将下面的代码复制到你的functions.php文件中,并将其中的>3改为你需要的上限值即可:

function send_email($from_name){
$count_email=(int)get_option('count_email');
$datetime = date('Y-m-d');
$sendemail_time=get_option('sendemail_time');
if($datetime!=$sendemail_time){
update_option('count_email', 1);
update_option('sendemail_time', $datetime);
return $from_name;
}else{
if($count_email>=3){
exit( __('The e-mail could not be sent.') . "<br />\n" . __('email is so big.') );
}else{
update_option('count_email', ($count_email+1));
update_option('sendemail_time', $datetime);
return $from_name;
}
}
}
add_filter( 'wp_mail_from_name', 'send_email', 10, 1 );

原理:
使用wordpress发信函数wp_mail上的过滤器来挂载我们的计数函数,然后将发信数量写入option数据表中,为了防止第二天不能发送,顺便把统计日期也写进去。然后每执行一次发送邮件函数,就会执行一次我们的计数函数,当发信数量达到我们限制的数量时,就终止发信函数,否则则正常返回。

《WordPress限制邮箱每天的发送数量》版权归逐凨所有
转载请保留原文链接:https://izhizu.com/wordpress/125.html
THE END
分享
二维码
< <上一篇
下一篇>>