Support » Plugins » [Plugin CF7] How to attach a file with the Post-title in reply mail

  • Hi there,

    I’m using the CF7 plug-in and came up to a nice piece of php code to implement some extra functionality to this great plug-in.

    If found it over here:Code

    But since this topic is closed I hope to get an answer on this new request.

    I implemented the code into my Functions.php and followed al instructions given in the particular post. The code is working fine, with my compliments to Daniele who wrote it, I only like to change a small thing and that’s where I got stuck.

    Before going to that, let me show the code first and give a small explanation on what it does and then after that go back to what I would like it to do.

    The Code:

    add_action( 'wpcf7_before_send_mail', 'create_unique_coupon_and_send_it' );
    function create_unique_coupon_and_send_it( $cf7 ) {
    	//check if this is the right form
    	if ($cf7->id==3475){
     		$uploads = wp_upload_dir();
    		//define some constants
    		define ('MY_FILE_PATH',$uploads['basedir'].'/subfolder/');
    		//set filenames
    		if ($cf7->mail['use_html']==true)
    		//make a copy of the master file and attach it
    		if ( copy( $master_copy, $copy_to_send ) ){
    			//Let'go to the file attachment!
    			$cf7->uploaded_files = array ( 'coupon' => $copy_to_send );
    		//append some text to the outgoing email
    		$message=$nl.$nl.'Blah blah blah.....'.$nl;
     		$message.='So Long, and Thanks for All the Fish!'.$nl;

    Basically it makes a copy from “master.pdf “ and copies it to the same directory under the name “copy.pdf”. After that the “copy.pdf” got attached to the reply mail (mail 2 option) by implementing short code [coupon] in the file attachments field.

    So far so good.

    Now is my idea is to place several PDF files in the “uploads/subfolder/” with the same names as the Posts where I’ve implemented the form.
    So if the Post is called “post-1” the file is called “post-1.pdf” etc. etc.

    Now I’m a complete newbie in PHP and even after reading PHP for Dummies I’m still not figured out how to do this, I really appreciate some help from the PHP crack who picks this request up.

    I assume that the change should be made in this line off code:
    In more ore less normal human language it should say:
    $master_copy=MY_FILE_PATH. “Current post title”. ‘.pdf’;

    So my question is how to get the “Current post title” in place…

    Thank you for your time, everyone!

    Greetings from Holland,

  • The topic ‘[Plugin CF7] How to attach a file with the Post-title in reply mail’ is closed to new replies.