Ad
How To Get Contact Email From Submitted Data In Contact Form 7?
I would like to subscribe the user to my other newsletter system using Contact Form 7. I tried to get the recipient email from the submitted form with the below code, but it returns sender (admin) email.
add_action('wpcf7_before_send_mail', function ($contact_form) {
$mailProp = $contact_form->get_properties('mail');
subscribe_to_another_newsletter($mailProp['mail']['recipient']);
});
How can I get the contact's data?
Ad
Answer
You want to grab your submission and then use the form field you used for email to do what you want with it.
add_action( 'wpcf7_before_send_mail', array($this, 'cf7_process_form'));
function my_cf7_process_form(){
// This calls the static get the cf7 form data
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
// $posted_data = array with all form fields
$posted_data = $submission->get_posted_data();
}
// if [your-email] is the form tag
$email = $posted_data['your-email'];
subscribe_to_another_newsletter($email);
}
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad