skip_mail no way out
-
After upgrading my website to the latest release of wp/wpcf7, some custom functions that I wrote for the older version of the plugin were not working anymore. Thanks to this post i solved most of the issues. Anyhow there is still one related to the skip_mail (i suppose) which is not working (I imagine I am not able to use it properly). This is my code:
/**
* This should skip mail based on the form id
*/
function my_custom_emailing( $wpcf7 ) {
if (( ID1==$wpcf7->id ) || ( YYY==$wpcf7->id )) {
$wpcf7->skip_mail = 1;
}
if ( ID2 == $wpcf7->id ) {
wp_redirect( ‘http://mysampleredirect’ );
$wpcf7->skip_mail = 1;
}
if ( ID3 != $wpcf7->id ) {
return $wpcf7;
}
if ( ID3 == $wpcf7->id ) {
if ( $wpcf7->posted_data ) {
if($wpcf7->posted_data[‘Item’][0]===’Register’) {
$wpcf7->skip_mail = 1;
}
}
return $wpcf7;
}
}
add_action( ‘wpcf7_before_send_mail’, ‘my_custom_emailing’);/*
* This adds custom recipients based for a given post ID and its parameters
*/
function set_question_form_recipient($components, $form, $object) {if (ID3 == $form->id()) {
$myStr = array(‘plant1’ => “custom@domain.com”,
‘plantX’ => “sample@mail.net”
);$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();if($posted_data[‘Item’][0]===’TVCC’) {
$components[‘recipient’] = $myStr[$posted_data[‘plant’]];
$components[‘additional_headers’] = ‘CC: my, custom, cc, comma, separated’;
}if($posted_data[‘Item’][0]===’Maintenance’) {
$components[‘recipient’] = ‘customrecipient@sample.net’;
$components[‘additional_headers’] = ‘CC: custom_cc@sample.net’;
}
}// Return the modified array (not sure if needed)
return $components;
}
add_filter(‘wpcf7_mail_components’, ‘set_question_form_recipient’, 10, 3);The code works as far as mail should not be skipped, otherwise I receive the standard error message complaining that “there was an error while sending the email”.
This should be due to the recipient not being set up, but I do not need to send the email so no recipient…I believe that the error is due to the skip_email not being handled properly.
Anyone could point me to the right direction?
Thanks
P.S. sorry if I am reposting this in a dedicated post, but I thought that having posted the issue in a misleading topic, marked as solved, wouldn’t have gained me any reply. I’ve searched across the forum for skip_mail issues but was not able to find a solution (at least I was not able to understand any…)
- The topic ‘skip_mail no way out’ is closed to new replies.