wp_mail 正在发送具有相同数据的消息
wp_mail is sending messages with same data
我对 wp_mail() 函数有疑问。它正确地向我发送了消息,但是在调用它之后向我发送了具有相同数据的多条消息,我应该如何正确地调用它或终止进程以仅发送一次?
下面是我如何调用 wp_mail()
// confirms reservation - doesn't matter for wp_mail()
$CLASS->ConfirmReservation($data);
// it gets all updated data about current reservation
$info = $CLASS->GetReservationInfo($_POST['operation_number'])[0];
// it prepares me array with parameters: to, subject, msg
$msgHTML = $CLASS->PrepareOrderHTMLmsg($info);
// adding headers to array
$msgHTML['headers'] = array('Content-Type: text/html; charset=UTF-8','From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>');
// send e-mail
wp_mail($msgHTML['send_to'], $msgHTML['subject'], $msgHTML['msg'] , $msgHTML['headers']);
从发送邮件的表单开始,当用户点击"send",用javascript捕获事件“onclick
”或"submit",你立即改变按钮 "send" 的状态为“disabled
”(这样你可以防止他们按下几次)然后在服务器端,在调用函数“wp_mail()
”后调用函数“ wp_die()
" 停止 php 脚本。
从其他页面我只是通过简单的 POST 将 FORM 收集的数据发送到付款 API ,作为响应我也得到了一些 POST 定义的数据 url 从下面调用函数
function DC_Shortcode(){
ob_start();
isset($_POST) ? DotpayCallback() : '';
return ob_get_clean();
}
add_shortcode('DCallback', 'DC_Shortcode');
// DOTPAY
function DotpayCallback() {
$CLASS= new CLASS();
$dotpaySettings = $BOANERGES->getDotpaySettings();
$PIN = $dotpaySettings[0]['pin_setting'];
$verify = 1; //verify data and save, requires valid PIN (above)
if($verify)
{
if($_SERVER['REQUEST_METHOD'] != 'POST') //URLC always uses POST
die($_SERVER['REQUEST_METHOD']." is incorrect request method");
if($_SERVER['REMOTE_ADDR'] != '195.150.9.37') //Dotpay IP for URLC is always 195.150.9.37
die("Unexpected IP: ".$_SERVER['REMOTE_ADDR']);
if(strlen($_POST['signature']) != '64') //signature always has 64 characters
die("Invalid POST content");
$sign=
$PIN.
$_POST['id'].
$_POST['operation_number'].
$_POST['operation_type'].
$_POST['operation_status'].
$_POST['operation_amount'].
$_POST['operation_currency'].
$_POST['operation_withdrawal_amount'].
$_POST['operation_commission_amount'].
$_POST['operation_original_amount'].
$_POST['operation_original_currency'].
$_POST['operation_datetime'].
$_POST['operation_related_number'].
$_POST['control'].
$_POST['description'].
$_POST['email'].
$_POST['p_info'].
$_POST['p_email'].
$_POST['credit_card_issuer_identification_number'].
$_POST['credit_card_masked_number'].
$_POST['credit_card_brand_codename'].
$_POST['credit_card_brand_code'].
$_POST['credit_card_id'].
$_POST['channel'].
$_POST['channel_country'].
$_POST['geoip_country'];
$signature = hash('sha256', $sign);
if($signature != $_POST['signature']) //compare POST signature with calculated one
die("Signature mismatch! Expected: ".$signature." Received: ".$_POST['signature']);
}
if($_POST['operation_status'] == 'completed') {
$data = array(
'id' => $_POST['operation_number'],
'control' => $_POST['control'],
'cs' => 1
);
// confirms reservation
$CLASS->ConfirmReservation($data);
// it gets all updated data about current reservation
$info = $CLASS->GetReservationInfo($_POST['operation_number'])[0];
// it prepares me array with parameters to, subject, msg
$msgHTML = $CLASS->PrepareOrderHTMLmsg($info);
// adding headers to array
$headers = array('Content-Type: text/html; charset=UTF-8','From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>');
// send e-mail
wp_mail($msgHTML['send_to'], $msgHTML['subject'], $msgHTML['msg'] , $headers);
wp_die();
die();
}
if($_POST['operation_status'] == 'rejected' || $_POST['operation_status'] == 'fail'){
$data = array(
'id' => $_POST['operation_number'],
'control' => $_POST['control'],
'cs' => 2
);
$CLASS->ConfirmReservation($data);
}
}
我对 wp_mail() 函数有疑问。它正确地向我发送了消息,但是在调用它之后向我发送了具有相同数据的多条消息,我应该如何正确地调用它或终止进程以仅发送一次?
下面是我如何调用 wp_mail()
// confirms reservation - doesn't matter for wp_mail()
$CLASS->ConfirmReservation($data);
// it gets all updated data about current reservation
$info = $CLASS->GetReservationInfo($_POST['operation_number'])[0];
// it prepares me array with parameters: to, subject, msg
$msgHTML = $CLASS->PrepareOrderHTMLmsg($info);
// adding headers to array
$msgHTML['headers'] = array('Content-Type: text/html; charset=UTF-8','From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>');
// send e-mail
wp_mail($msgHTML['send_to'], $msgHTML['subject'], $msgHTML['msg'] , $msgHTML['headers']);
从发送邮件的表单开始,当用户点击"send",用javascript捕获事件“onclick
”或"submit",你立即改变按钮 "send" 的状态为“disabled
”(这样你可以防止他们按下几次)然后在服务器端,在调用函数“wp_mail()
”后调用函数“ wp_die()
" 停止 php 脚本。
从其他页面我只是通过简单的 POST 将 FORM 收集的数据发送到付款 API ,作为响应我也得到了一些 POST 定义的数据 url 从下面调用函数
function DC_Shortcode(){
ob_start();
isset($_POST) ? DotpayCallback() : '';
return ob_get_clean();
}
add_shortcode('DCallback', 'DC_Shortcode');
// DOTPAY
function DotpayCallback() {
$CLASS= new CLASS();
$dotpaySettings = $BOANERGES->getDotpaySettings();
$PIN = $dotpaySettings[0]['pin_setting'];
$verify = 1; //verify data and save, requires valid PIN (above)
if($verify)
{
if($_SERVER['REQUEST_METHOD'] != 'POST') //URLC always uses POST
die($_SERVER['REQUEST_METHOD']." is incorrect request method");
if($_SERVER['REMOTE_ADDR'] != '195.150.9.37') //Dotpay IP for URLC is always 195.150.9.37
die("Unexpected IP: ".$_SERVER['REMOTE_ADDR']);
if(strlen($_POST['signature']) != '64') //signature always has 64 characters
die("Invalid POST content");
$sign=
$PIN.
$_POST['id'].
$_POST['operation_number'].
$_POST['operation_type'].
$_POST['operation_status'].
$_POST['operation_amount'].
$_POST['operation_currency'].
$_POST['operation_withdrawal_amount'].
$_POST['operation_commission_amount'].
$_POST['operation_original_amount'].
$_POST['operation_original_currency'].
$_POST['operation_datetime'].
$_POST['operation_related_number'].
$_POST['control'].
$_POST['description'].
$_POST['email'].
$_POST['p_info'].
$_POST['p_email'].
$_POST['credit_card_issuer_identification_number'].
$_POST['credit_card_masked_number'].
$_POST['credit_card_brand_codename'].
$_POST['credit_card_brand_code'].
$_POST['credit_card_id'].
$_POST['channel'].
$_POST['channel_country'].
$_POST['geoip_country'];
$signature = hash('sha256', $sign);
if($signature != $_POST['signature']) //compare POST signature with calculated one
die("Signature mismatch! Expected: ".$signature." Received: ".$_POST['signature']);
}
if($_POST['operation_status'] == 'completed') {
$data = array(
'id' => $_POST['operation_number'],
'control' => $_POST['control'],
'cs' => 1
);
// confirms reservation
$CLASS->ConfirmReservation($data);
// it gets all updated data about current reservation
$info = $CLASS->GetReservationInfo($_POST['operation_number'])[0];
// it prepares me array with parameters to, subject, msg
$msgHTML = $CLASS->PrepareOrderHTMLmsg($info);
// adding headers to array
$headers = array('Content-Type: text/html; charset=UTF-8','From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>');
// send e-mail
wp_mail($msgHTML['send_to'], $msgHTML['subject'], $msgHTML['msg'] , $headers);
wp_die();
die();
}
if($_POST['operation_status'] == 'rejected' || $_POST['operation_status'] == 'fail'){
$data = array(
'id' => $_POST['operation_number'],
'control' => $_POST['control'],
'cs' => 2
);
$CLASS->ConfirmReservation($data);
}
}