wpcf7_sanitize_mail

The Contact Form 7 wpcf7 sanitize mail function.

Description

wpcf7_sanitize_mail( $input, (array) $defaults = array() ); 

Parameters (2)

0. $input
The input.
1. $defaults — Optional. (array) => array()
The defaults.

Usage

  1. if ( !function_exists( 'wpcf7_sanitize_mail' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/contact-form-functions.php'; 
  3.  
  4. // The input. 
  5. $input = null; 
  6.  
  7. // The defaults. 
  8. $defaults = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wpcf7_sanitize_mail($input, $defaults); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/contact-form-functions.php  
  1. function wpcf7_sanitize_mail( $input, $defaults = array() ) { 
  2. $defaults = wp_parse_args( $defaults, array( 
  3. 'active' => false,  
  4. 'subject' => '',  
  5. 'sender' => '',  
  6. 'recipient' => '',  
  7. 'body' => '',  
  8. 'additional_headers' => '',  
  9. 'attachments' => '',  
  10. 'use_html' => false,  
  11. 'exclude_blank' => false,  
  12. ) ); 
  13.  
  14. $input = wp_parse_args( $input, $defaults ); 
  15.  
  16. $output = array(); 
  17. $output['active'] = (bool) $input['active']; 
  18. $output['subject'] = trim( $input['subject'] ); 
  19. $output['sender'] = trim( $input['sender'] ); 
  20. $output['recipient'] = trim( $input['recipient'] ); 
  21. $output['body'] = trim( $input['body'] ); 
  22. $output['additional_headers'] = ''; 
  23.  
  24. $headers = str_replace( "\r\n", "\n", $input['additional_headers'] ); 
  25. $headers = explode( "\n", $headers ); 
  26.  
  27. foreach ( $headers as $header ) { 
  28. $header = trim( $header ); 
  29.  
  30. if ( '' !== $header ) { 
  31. $output['additional_headers'] .= $header . "\n"; 
  32.  
  33. $output['additional_headers'] = trim( $output['additional_headers'] ); 
  34. $output['attachments'] = trim( $input['attachments'] ); 
  35. $output['use_html'] = (bool) $input['use_html']; 
  36. $output['exclude_blank'] = (bool) $input['exclude_blank']; 
  37.  
  38. return $output;