gpt4 book ai didi

php - (Wordpress) Contact Form 7 在 before_send_mail 过滤器中中止

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:38:08 25 4
gpt4 key购买 nike

我在我的 WordPress 网站上使用 Contact Form 7 作为邮件系统。我使用 wpcf7_before_send_mail 过滤器将所有数据发送到外部网络服务 (SOAP)。当我收到该网络服务的“SUCCESS”消息时,一切都应该照常进行,但是当我收到“FAILED”消息时,联系表 7 不应发送电子邮件,并且网站上应该出现不同的输出消息。是否可以在函数内更改它?

<?

add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

add_action('wpcf7_before_send_mail', 'wpcf7_soap_service');


//Pushen via SOAP service naar servers
function wpcf7_soap_service($contact_form) {
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {

/*** POST variabelen ***/
$posted_data = $submission->get_posted_data();

/*** SOAP settings ***/
ini_set("soap.wsdl_cache_enabled", "0");

/*** variabelen opzetten ***/
define('BROADCAST_URL','XXX');
define('SIM_LOGIN', 'XXX');
define('SIM_PASSWORD', 'XXX');
define('ENV_KEY', 'XXX');

/*** login parameters ***/
$params = array(
'username' => SIM_LOGIN,
'password' => SIM_PASSWORD,
'environmentKey' => ENV_KEY,
);

/*** client opzetten ***/
$client = new SoapClient(
BROADCAST_URL,
array(
'soap_version' => SOAP_1_1
)
);

/*** Parameters ***/
$address["box"] = $posted_data["box"];
$address["country"] = $posted_data["country"];
$address["number"] = $posted_data["streetnumber"];
$address["postalcode"] = $posted_data["postalcode"];
$address["street"] = $posted_data["street"];
$address["town"] = $posted_data["town"];

$birthdate = $posted_data["birthdate"] . "T00:00:00";
$email = $posted_data["email"];

$firstname = $posted_data["firstname"];
$lastname = $posted_data["lastname"];
$phone = $posted_data["phone"];

/*** STDClass aanmaken met gevraagde data ***/
$std = new stdClass();

$std->Firstname = $firstname;
$std->Lastname = $lastname;
$std->Birthdate = $birthdate;
$std->Phone = $phone;
$std->Email = $email;

$std->Address = new stdClass();

$std->Address->Street = $address["street"];
$std->Address->Number = $address["number"];
$std->Address->Box = $address["box"];
$std->Address->PostalCode = $address["postalcode"];
$std->Address->Town = $address["town"];
$std->Address->Country = $address["country"];

if(!empty($_FILES['cv'])){

$std->Files = new stdClass();

$std->Files->File["FileName"] = $_FILES["cv"]["name"];
$std->Files->File["DataFile"] = base64_encode($_FILES["cv"]["tmp_name"]);
$std->Files->File["FileType"] = "CV";
}

/*** Functie OpenSession ***/
try{
$token = $client->OpenSession($params);
}catch(SoapFault $ex){
// ABORT OVER HERE
}

$token = $token->OpenSessionResult;

/*** Functie AddApplication ***/
try{
$result = $client->AddApplication(array("token" => $token, "application" => $std));
}catch(SoapFault $ex){
// ABORT OVER HERE
}

if($result->AddApplicationResult->Status == "Success"){
// ABORT OVER HERE
}


/*** Functie CloseSession ***/
try{
$app = $client->CloseSession($token);
}catch(SoapFault $ex){
// ABORT OVER HERE
}

}
}

最佳答案

您可以使用以下方式跳过邮件:

add_filter( 'wpcf7_skip_mail',  '__return_true' );

因为你已经禁用了javascript

add_filter( 'wpcf7_load_js', '__return_false' );

然后你可以使用:

add_filter( 'wpcf7_form_response_output', 'wpse_form_response_output', 10, 4 );

在您的 wpcf7_before_send_mail 操作回调中,您的自定义错误响应是:

function wpse_form_response_output( $output, $class, $content, $object )
{
return sprintf(
'<div class="wpcf7-response-output wpcf7-display-none wpcf7-mail-sent-ng"
role="alert" style="display: block;">%s</div>',
__( 'SOAP ERROR - Mail not sent!' )
);
}

关于php - (Wordpress) Contact Form 7 在 before_send_mail 过滤器中中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32711320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com