Last active
November 7, 2024 22:12
-
-
Save ianhampton/eee8f8ea1a6280db8bbae3944c07a451 to your computer and use it in GitHub Desktop.
Dynamically add file attachments to Contact Form 7 emails from a custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Dynamically add file attachments to Contact Form 7 emails from a Wordpress custom field. | |
| * Custom field is 'case-pdf' in the example. | |
| */ | |
| add_action('wpcf7_before_send_mail', 'wpcf7_add_attachment'); | |
| function wpcf7_add_attachment($contact_form) { | |
| global $_POST; | |
| $submission = WPCF7_Submission::get_instance(); | |
| if ( $submission && !empty($_POST['case-pdf']) ) { | |
| $mail = $contact_form->prop('mail'); | |
| $mail['attachments'] .= $_POST['case-pdf']; | |
| $contact_form->set_properties(array('mail' => $mail)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been ending on the exact same solution :-)
I should have found this post earlier !