• Resolved mlchrt

    (@mlchrt)


    Hi there,

    is it possible to attach a PDF directly to the submit notification? The PDF should be the same for each submit notification reaching the customer without attaching the data send via file upload from the sender. One use case could be to attach the ToS of the shop or other formal documents. I saw a similar question was asked to years ago with the solution the feature will be added. Are there any updates or workaround I could use to solve this. To attach a link is not the optimal solution, as the document should be delivered with the submit notification but only with the notification reaching the sender of the form.

    Thanks for any help in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @mlchrt

    I hope you are doing well.

    This feature is still under development and its release will depend on the current roadmap. Meanwhile, an alternative is to add a must-use plugin to your site’s wp-content/mu-plugins folder like this?https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code to the plugin’s php?file:

    <?php
    add_filter( 'forminator_custom_form_mail_admin_headers', 'wpmudev_change_forminator_header_attachment', 10, 5 );
    function wpmudev_change_forminator_header_attachment( $headers, $custom_form, $data, $entry, $cls ) {
    	if ( $custom_form->id != 6) { //Please change the form ID
    		return $headers;
    	}
    
    	$headers[] = 'X-FORMINAT-ATTCH : true';
    
    	return $headers;
    }
    
    add_filter('wp_mail', 'wpmudev_attach_pdf_forminator', 10, 1);
    function wpmudev_attach_pdf_forminator( $args ) {
    	if ( is_array( $args['headers'] ) ) {
    		foreach( $args['headers'] as $key => $value ) {
    			if ( strpos( $value, 'X-FORMINAT-ATTCH' ) !== false ) {
    $args['attachments'][] = WP_CONTENT_DIR.'path_of_your_pdf_file';
    			}
    		}
    	}
    	return $args;
    }

    Note: In the code please change 6 to your form’s ID. Also, please change path_of_your_pdf_file to your PDF file’s path.

    We recommend to test this on the dev/staging version first before putting it on the live site.

    Hope this info is helpful.

    Kind regards

    Luis

    Thread Starter mlchrt

    (@mlchrt)

    Great, thanks Luis! A really good starting point. Is there anyway to limit this is a certain submit notification or are now all e-mail notifications in the mentioned form attached with a pdf? If I’ve got two replys. One for the admin and one for the submitter, how can I just attach the pdf to the submitter not the admin notification?

    • This reply was modified 1 year, 6 months ago by mlchrt.
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @mlchrt

    It will affect all notifications from given form. If you only want to apply it to one of those notifications, you can do so with a bit of a “trick”:

    1. First, make sure that the notification to which you want to attach PDF has some unique word or phrase included in subject; by “unique” I mean that it’s “fixed” (so it’s always there – not value of the filed but just some string) and it is used only in this particular notification’s subject.

    2. Second replace this part of previously shared code

    function wpmudev_attach_pdf_forminator( $args ) {
    	if ( is_array( $args['headers'] ) ) {
    		foreach( $args['headers'] as $key => $value ) {
    			if ( strpos( $value, 'X-FORMINAT-ATTCH' ) !== false ) {
    $args['attachments'][] = WP_CONTENT_DIR.'path_of_your_pdf_file';
    			}
    		}
    	}
    	return $args;
    }

    with this

    function wpmudev_attach_pdf_forminator( $args ) {
    	
    	if ( strpos( $args['subject'], 'SOMETHING_UNIQUE' ) !== false ) {
    	
    		if ( is_array( $args['headers'] ) ) {
    			foreach( $args['headers'] as $key => $value ) {
    				if ( strpos( $value, 'X-FORMINAT-ATTCH' ) !== false ) {
    					$args['attachments'][] = WP_CONTENT_DIR.'path_of_your_pdf_file';
    				}
    			}
    		}
    		
    	}
    	
    	return $args;
    }

    3. And finally, in this code replace SOMETHING_UNIQUE with that word or phrase from notification subject.

    The way it works is that before attaching PDF it checks if defined word/phrase exists in notification subject – if not, it skips attaching PDF; if yes, it attaches it.

    Best regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @mlchrt ,

    We haven’t heard from you for some time now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Attach PDF to form submit notification’ is closed to new replies.