• Resolved kender

    (@kender)


    I am attempting to include the filename only of uploaded files in the confirmation email (mail 2)

    I have tried editing it via ‘wpcf7_additional_email’ filter which should fire directly before sending, but it is not removing the url

        // below is find/replace for the domain and path to the file upload location
        function customize_mail_2($additional_mail, $contact_form) {
          $submission = WPCF7_Submission::get_instance();
          $wpcf7      = WPCF7_ContactForm::get_current();
       
          $additional_mail['mail_2']['body'] = str_replace('{domain}/wp-content/uploads/wp_dndcf7_uploads/wpcf7-files/', '', $additional_mail['mail_2']['body']);
          return $additional_mail;
        }
        add_filter('wpcf7_additional_mail', 'customize_mail_2', 10, 2);

    when I replace the line where it does the find/replace with an append, that works, so I know I am in the right area

        // example
        $additional_mail['mail_2']['body'] .= '...' // the "..." will show at end of email

    any idea where i may be doing this wrong, or an idea on how to do it correctly?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Glen Don Mongaya

    (@glenwpcoder)

    Hello @kender ,

    I think your filter is correct, but $additional_mail variable doesn’t have any HTML content yet.

    Can you try this code:

    function customize_mail_2($additional_mail, $contact_form) { 
    		$submission = WPCF7_Submission::get_instance();		
    		if( $submission ) {
    			$links = array();
    			$fields = $contact_form->scan_form_tags();			
    			$submitted['posted_data'] = $submission->get_posted_data();
    			foreach( $fields as $field ) {
    				if( $field->basetype == 'mfile') {
    					if( isset( $submitted['posted_data'][$field->name] ) && ! empty( $submitted['posted_data'][$field->name] ) ) {
    						if( is_array( $submitted['posted_data'][$field->name] ) ) {
    							foreach( $submitted['posted_data'][$field->name] as $link ) {
    								$links[] = wp_basename( $link );
    							}
    						}						
    						$mail_body = $additional_mail['mail_2']['body'];
    						$additional_mail['mail_2']['body'] = str_replace( "[$field->name]", "\n" . implode( "\n" , $links ), $mail_body );
    					}
    				}
    			}
    		}
    		
    		return $additional_mail;
        }
        add_filter('wpcf7_additional_mail', 'customize_mail_2', 10, 2);
    Thread Starter kender

    (@kender)

    That worked perfectly, thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘editing mail_2 output for filenames only’ is closed to new replies.