• Currently, the contact form sends me an email, as well as sends the user a confirmation email.

    Is it possible to include an attachment to the user? Specifically, if I were running a charity for an event, and they registered using Contact Form 7, would it be possible to send a pledge form and an informational pdf to them with the confirmation email?

    Note: This is unrelated to the file attachment tags, I am not trying to get people to upload an attachment to send to me, I am trying to send an attachment back to them.

    Thank you for your time, everyone! I hope to get this resolved soon.

    https://www.ads-software.com/extend/plugins/contact-form-7/

    Edit: Etiquette.

Viewing 15 replies - 16 through 30 (of 32 total)
  • G Matta

    (@gangesh)

    @mad_max

    Thanks for such elaborate explanation. ??
    Works great!

    @mad_max

    I an trying to attach a file hosted on a different site that I own.
    Can’t make it work using your code.
    Can you help?

    @tari72

    php copy should support remote files, so just change the path to your master file:

    $master_copy='https://www.mysite.it/subfolder/private/my_remote_file.pdf';

    IF IT DOESN’T WORK
    here you can find a good tutorial with 4 solutions to read a remote file and grab its content.

    Once you have putted the content of the remote file in to a variable ($content in the tutorial), just write it to a file with a line of code like this:

    file_put_contents($file, $content);

    Suppose you decide to use the second method described in the tutorial (remember to verify that your hosting service has allow_url_fopen setted to true in php.ini), you can integrate it in my code like this:

    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==741){
     		$uploads = wp_upload_dir();
    		//define some constants
    		define ('MY_FILE_PATH',$uploads['path'].'/myfile/');
    
    		//set filenames
    		$master_copy='https://www.mysite.it/subfolder/private/my_remote_file.pdf';
    		$copy_to_send=MY-FILE_PATH.'attachment.pdf';
    
    		if ($cf7->mail['use_html']==true)
    			$nl="<br/>";
    		else
    			$nl="\n";
    		// get the remote file
    		$content = file_get_contents('$master_copy');
    		if ($content !== false) {
    			//make a copy of the master file and attach it
    			if ( file_put_contents($copy_to_send, $content) !== false ){
    				//Let'go to the file attachment!
    				$cf7->uploaded_files = array ( 'coupon' => $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;
    		$cf7->mail_2['body'].=$message;
    	}
    }

    hi mad_max

    can’t make it work.
    would you be kind enough to write a simplified code.
    without the upload path minimum if(s) as basic as possible.
    once i can attach a file (not upload) i guess i’ll figure every thing else.

    Thanks a lot for your time.
    Really appreciate it.

    Dayum, just can’t get it working. Everything works for me apart from the attachment, I get the email about the fish and the form submits nicely, but no attachment.

    I’m using the method to send the same file each time.

    Has anything changed with the latest version of cf7?

    @tari72: Do you have some errors? What do you mean with “can’t make it work.”
    Can you make more clear which is the obscure part in my code, so I can help with it?

    @palgrave: I don’t think so. I’m using the last CF7 version and it works. Which version of WP are you using? Have you added a field name in the file attachement field on MAIL section?

    @mad_max First of all thanks for the quick reply. That sets you apart ??

    I’m using WP 3.3.1 and I just used [coupon] in the file attachment field.

    mmmh, I’m using this file attachment method on a 3.2.1 WP version but I think the problem is not due to the your newer WP version. Can you attach the code you are using?

    I actually got it working in the meantime using $recipient_email = $cf7->posted_data[“your-email”] and then a regular mail function.

    Thank you very much for your help, and for posting the only thing anywhere on the internet that signposted it for me.

    You are welcome! Happy to hear you have resolved your issue.

    took me a while to answer but i get no errors just like palgrave.
    every thing seems to work but the attachment thing.
    mad max – thanks for the time and effort.
    palgrave – can you attach the code you used?
    what is a regular mail function.
    i got to make this work.

    Mad Max, thanks so much for your excellent posts on this issue, I got it working thanks to you.

    @mad_max,

    First of Thank you. I finally go it to work.
    I’m new to WP PHP and the web.
    problem was I tried to attach a file and gave a wrong path.

    again thanks,
    your solution makes CF7 a lot better and complete solution

    Tari72

    Can someone assist me please. I wish to use the page slug as the name of the PDF file. I tried to assign the slug as below:

    global $post
    $slug = $post->post_name;
    $master_copy=MY_FILE_PATH.$slug.’.pdf’;

    But it seems this doesn’t work. I’m a bit lost so any direction would be much appreciated.

    @daniele
    Thanks for sharing your solution but I couldn’t get it to work. I also get the message with “So Long,…” but no attachment. So I tried to follow your instructions for installing and using FirePHP Firefox extension to Firebug and wp-firePHP plugin for WordPress. Nuts! After hours of reading the documentation (what there is) for both and studying your instructions I still don’t understand:
    1. Where on my website server or local testing (wamp) directory to put the FirePHPCore library.

    2. Which file to put in “require_once(‘FirePHPCore/FirePHP.class.php’);” and “ob_start();”

    3. Where in firebug to enter “fb($cf7);”

    4. Why I don’t see a url listed under Console even though FirePHP (the blue bug) is enabled. All I see under console is “Clear Persist Profile All Errors Warnings Info Debug Info”.

    I’ve looked here:https://www.firephp.org/HQ/Learn.htm and here: https://www.sitepoint.com/debug-php-firebug-firephp/ but I can’t make monkey poop out of either. Man, I’m not a newb to code, just haven’t debugged PHP before. Why does the documentation have to be so vague?!
    Please help.

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘[Plugin: Contact Form 7] Sending Attachments, Without User Upload’ is closed to new replies.