WordPress.org

Forums

Contact Form 7
file-uploading-and-attachment (5 posts)

  1. squizeers
    Member
    Posted 1 year ago #

    Hi,
    Attachment solution explained in http://contactform7.com/file-uploading-and-attachment/#local-file-attachment is very interesting. Is it possible to populate that "File attachments" field dynamically-from function.php?

    What I am trying to do is, I have posts with list of pdfs attached. I want form on each post when submitted, the pdfs from the post will be attached in the email.

    I went through the following but it didnt work.
    https://osamaahmedattia.wordpress.com/2013/01/15/contact-7-send-email-with-auto-attachment/

    Thank you.

    https://wordpress.org/plugins/contact-form-7/

  2. squizeers
    Member
    Posted 1 year ago #

    Very close to what I want :

    add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
    
    function mycustom_wpcf7_mail_components( $components ) {
    	$components['attachments'][] = 'wp-content/uploads/pdf/r.maharjan.pdf';
    
    	return $components;
    }

    Now I have to collect the PATH of all the pdfs listed in a post. HOW?

  3. squizeers
    Member
    Posted 1 year ago #

    WHY IS THE NOT WORKING?
    The emails doesn't get send... the sending gif animation loads forever...

    function mycustom_wpcf7_mail_components( $components ){
    
    		$sheets = rwmb_meta( 'brand_sell_sheet', $args = array('type'=>'file' ), $post_id = null );
    			foreach($sheets as $key => $value){
    				$path.= "'".ltrim($value["path"],'public_html/project/hain/')."',";
    			}
    		$attachments = rtrim($path,",");
    
    		$components['attachments']= array($attachments);
    		return $components;
    	}
    
    	add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
  4. squizeers
    Member
    Posted 1 year ago #

    This is the closest I could get but still not working.

    add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
    	function mycustom_wpcf7_mail_components( $components ){
    		$differentarray = array(); 
    
    		$sheets = rwmb_meta( 'brand_sell_sheet', $args = array('type'=>'file' ), $post_id = null );
    		foreach($sheets as $value){
    			$differentarray[] = ltrim($value["path"],'/home/rajumaha/public_html/project/hain/');
    		}
    		//print_r ($differentarray);
    		$components['attachments']= $differentarray;
    		return $components;
    	}
  5. squizeers
    Member
    Posted 1 year ago #

    I am so tired now... Both functions below result the same. You can see the result here.

    This one works, sends the attachments.Attachments are hard coded.

    /*WORKING*/
    	add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components1' );
    	function mycustom_wpcf7_mail_components1( $components ) {
    		$components['attachments'] = array('wp-content/uploads/2014/02/JASON-Deodorant1.pdf','wp-content/uploads/2014/02/JASON-Dandruff.pdf');
    
    		return $components;
    	}
    /*WORKING*/

    This one does not work. Attachments are dynamically pulled from the custom meta box.

    /*NOT WORKING*/
    	add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components2' );
    	function mycustom_wpcf7_mail_components2( $components ){
    
    		$differentarray = array();
    		$sheets = rwmb_meta( 'brand_sell_sheet','type=file' );
    		foreach ((array)$sheets as $value) {
    			$differentarray[]= ltrim($value["path"],'/home/rajumaha/public_html/project/hain/');
    		}
    		$components['attachments']= $differentarray;
    		return $components;
    	}
    /*NOT WORKING*/

    Somebody please help

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic