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

当用户执行正确的处理时,我想要的是避免在没有数据的情况下生成电子邮件。
发布于 2018-08-10 15:58:52
做一个快速检查,以确保一个必需的$_POST支付变量是存在的,而不是空的。
所以在你的文件顶部
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插件的元索引一样简单。
https://wordpress.stackexchange.com/questions/311067
复制相似问题