Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] using a variable as address to send the mail to

  • I run a wordpress site that features various circus artists. each page a contact information that is takes form the meta-data entered for each show. I would like to use the e-mail stored in the meta-data.

    $mail = get_post_meta( $post->ID, ‘mail’, true );

    I would like to use $mail as the recipient of the mail sent through the contact form 7 – different recipient for each page…

    How? Ideas?

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Add this code to your theme’s functions.php:

    add_filter( 'wpcf7_special_mail_tags', 'my_wpcf7_special_mail_tag_for_mail_meta', 10, 2 );
    
    function my_wpcf7_special_mail_tag_for_mail_meta( $output, $name ) {
    
    	if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
    		return $output;
    
    	if ( ! preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $_POST['_wpcf7_unit_tag'], $matches ) )
    		return $output;
    
    	$post_id = (int) $matches[2];
    
    	if ( ! $post = get_post( $post_id ) )
    		return $output;
    
    	if ( '_my_mail_meta' == $name ) {
    		$mail = get_post_meta( $post->ID, 'mail', true );
    		$output = $mail;
    	}
    
    	return $output;
    }

    Then insert [_my_mail_meta] to the To field in the Mail section.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Contact Form 7] using a variable as address to send the mail to’ is closed to new replies.