Removing special characters and carriage returns from text area?
-
I’m a php noob, I’ve tried hacking something together using the ‘wpcf7_before_send_mail’ and I’m coming up just a bit short.
Anyone have any examples of modifying field values before sending emails?
add_action('wpcf7_before_send_mail', 'save_form' ); function save_form( $wpcf7 ) { $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); $newString = [your-message]; $myText = (string)$newString; $newText = preg_replace('/[^a-zA-Z0-9\']/', '', $myText); $mail = $wpcf7->prop('mail'); // Find/replace the tag as defined in your CF7 email body $mail['body'] = str_replace('[your-message]', $newText, $mail['body']); $mail2 = $wpcf7->prop('mail_2'); //$mail2['body'] = str_replace("[your-message]", $newText, $mail2['body']); $wpcf7->set_properties(array("mail" => $mail,"mail_2" => $mail2)); }
- The topic ‘Removing special characters and carriage returns from text area?’ is closed to new replies.