• 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…)

Viewing 1 replies (of 1 total)
  • Thread Starter moviemaniac

    (@moviemaniac)

    Time is not on my side, unfortunately. So I had to go on and try to understand how to fix things.
    I came out with this solution, after a bit of trial and error, it is not the best one obvioulsy, but it is working as expected. I beg the author of the plugin to please give a bit of support on this. I do not want to mislead anyone.

    The below filter looks at the form id and acts consequently. I have a form with three options (checkboxes) which the submitter can choose alternatively. And then I need to send out an email in two cases out of three (need not to send it for a given option), plus I have several other forms for which I do not have to send out email at all.

    /**
    * $skip_mail is true or false, tells whether to send email or not 
    * $wpcf7 is the current form template (not the data sent through it!!!)
    */
    function mycustom_wpcf7_skip_mail( $skip_mail, $wpcf7 ) {
    	if (( ID1==$wpcf7->id() ) || ( ID2==$wpcf7->id() )) {
    		return true;
    	}
    	
    	if ( ID3 == $wpcf7->id() ) {
    		// redirect after the form has been submitted
            $wpcf7->set_properties( array(
                'additional_settings' => "on_sent_ok: \"location.replace('http://ID3-REDIRECT//');\"",
            ) );
    	}
    
    	//	[.....]
    	
    	if ( IDN != $wpcf7->id() ) {
    		return true;
    	}
    	
    	/*
    	    $instance = WPCF7_Submission::get_instance();
            $posted_data = $instance->get_posted_data();
    		** The above two lines of code are equivalent to the following line, but more readable
    	*/
    	
        $posted_data = WPCF7_Submission::get_instance()->get_posted_data("MYITEM");
    
    	if($posted_data[0]==='MYITEM SPECIAL CONTENT NOT TO MAIL TO') {
    		return true;
    	}
    	return $skip_mail = false;
    }
    add_filter( 'wpcf7_skip_mail', 'mycustom_wpcf7_skip_mail', 10, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘skip_mail no way out’ is closed to new replies.