首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每天发邮件,怎么阻止?

问每天发邮件,怎么阻止?
EN

WordPress Development用户
提问于 2018-08-10 15:14:11
回答 1查看 26关注 0票数 1

我有一个带有页面模板的页面,该页面通过post方法接收数据(数据在支付网关中处理,响应被发送到wordpress),这些数据在模板中处理,创建一个使用wp_mail ()函数通过电子邮件作为消息正文发送的html文档,如果用户执行该过程,则生成并正确发送电子邮件,即使有附件,用户和相应的工作人员也会收到另一个版本,问题是每天都有空邮件到达员工,我想知道如何避免这一点?我就是这样发邮件的

代码语言:javascript
复制
$subject = "Payment Options";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Return-Path: "."\n";
$message = "builded HTML"; 

function ejr_email_desde ($email) {
    return "email@from.com";
    }

add_filter ("wp_mail_from", "ejr_email_desde");

$attach = array('path to attached files');
$sent = wp_mail("info@email.com", $subject, $message,$headers, $attach);
wp_mail("staff1@email.com", $subject, $message,$headers, $attach);
wp_mail("staff2@email.com", $subject, $message,$headers, $attach);
wp_mail("staff3@email.com", $subject, $message,$headers, $attach);
wp_mail("staff4@email.com", $subject, $message,$headers, $attach);


$subject = "Subject";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "The builded HTML"; 
$attachments = array('path to attachment');

wp_mail('client@email', $subject, $message,$headers,$attachments); 

这是空html。

当用户执行正确的处理时,我想要的是避免在没有数据的情况下生成电子邮件。

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2018-08-10 15:58:52

做一个快速检查,以确保一个必需的$_POST支付变量是存在的,而不是空的。

所以在你的文件顶部

代码语言:javascript
复制
if(!empty($_POST['paymentinfovariable'])) {
    // put all your current code here
    // that way POST info is only processed, and email is only sent,
    // if your required variable has been properly POSTed.
} else {
// redirect to the homepage
    wp_redirect( home_url() );
    exit;
}

这样,如果缺少必需的post变量--意味着有人正在访问URL --他们将被重定向到主页,不会发送电子邮件。您可以更进一步,检查POSTed变量是否具有正确的格式、来自正确的引用域等,以进一步保护您的安全性。

你可能也应该看看你的站点地图--人们(或机器人)点击这个页面是有原因的,这可能就像把你的站点地图设置为使用任何SEO插件的元索引一样简单。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/311067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档