Created
February 21, 2025 21:35
-
-
Save connormesec/36f75e3e438ac5ad80812bb95f3f15a6 to your computer and use it in GitHub Desktop.
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
| // This works on an AWS Lightsail instance using WP Mail SMTP and is current as of Feb 2025 | |
| // Place this code in your functions.php file in your divi-child theme | |
| // This sends a copy of any message sent via the Divi contact form module to a predetermined email | |
| function send_copy_of_contact_email( $processed_fields_values, $et_contact_error, $form_data ) { | |
| $admin_email = get_option( 'admin_email' ); // Change if needed | |
| $subject = "New message from " . get_bloginfo( 'name' ) . " - Copy"; | |
| // Exit if no data or error | |
| if ( empty( $processed_fields_values ) || !empty( $et_contact_error ) ) { | |
| return; | |
| } | |
| // Initialize message | |
| $message = ""; | |
| // Ensure we loop through the form data correctly | |
| foreach ( $processed_fields_values as $fields => $field ) { | |
| if ( is_array( $field ) && isset( $field['value'] ) ) { | |
| $label = isset( $field['label'] ) ? $field['label'] : ucfirst(str_replace('_', ' ', $field_id)); | |
| $value = is_array( $field['value'] ) ? implode(', ', $field['value'] ) : $field['value']; // Handle array values | |
| $message .= "$label: $value\n"; | |
| } | |
| } | |
| // Email headers | |
| $headers = array('Content-Type: text/plain; charset=UTF-8'); | |
| // Send the email | |
| wp_mail( $admin_email, $subject, $message, $headers ); | |
| } | |
| add_action( 'et_pb_contact_form_submit', 'send_copy_of_contact_email', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment