英溯IT论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 20|回复: 0

Discuz! X3.4 限制国家和域名发送邮件

[复制链接]

109

主题

117

帖子

610

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
610
发表于 2025-2-16 18:39:32 | 显示全部楼层 |阅读模式
在 source/function/function_mail.php 里找到 function sendmail($toemail, $subject, $message, $from = '')
在 sendmail() 函数内添加:

$user_ip = $_SERVER['REMOTE_ADDR'];
$allowed_countries = array('CN', 'JP');
$ip_info = json_decode(file_get_contents("http://ip-api.com/json/{$user_ip}?fields=countryCode"), true);
if (!in_array($ip_info['countryCode'], $allowed_countries)) {
     return false; // 禁止发送邮件
}

----------------------------------------------域名---------------------------------------
function sendmail($toemail, $subject, $message, $from = '') {
     global $_G;
     // 黑名单邮件域名
     $blacklist_domains = array('1tetris.ru', 'example.com', 'spamdomain.net');
     // 提取收件人邮箱的域名
     $email_domain = substr(strrchr($toemail, "@"), 1);
     // 如果域名在黑名单中,则不发送邮件
     if (in_array($email_domain, $blacklist_domains)) {
         return false; // 直接返回,不发送邮件
     }
     // 继续执行原始的邮件发送逻辑    ...
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|英溯IT论坛 ( 沪ICP备13022730号-6 )

GMT+8, 2025-3-12 09:38 , Processed in 0.110741 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表