'logged-in user’s information in contact for 7 plugin
I have 2 users in WordPress. One is admin and another is a contributor.
I am trying to send email using the contact form 7 plugin.
I logged in by contributor user. I need to send user (contributor) details like email. I use a code default:user_display_name and [email* your-email default:user_email] in message body field. Both of them are not useful.
If I use [_site_admin_email] email of admin is sent. I want to send the logged-in user email.
Solution 1:[1]
You should use wpcf7_before_send_mail action hook to add user's info in your email body. Below is an example on how you can do that.
add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );
function wpcf7_add_text_to_mail_body($contact_form){
$form_id = $contact_form->posted_data['_wpcf7']; // Get for ID
if ($form_id == 123): // 123 => Your Form ID.
$current_user = wp_get_current_user(); // Get Current User Object
$user_email = $current_user->user_email;
// get mail property
$mail = $contact_form->prop( 'mail' ); // returns array
// add content to email body
$mail['body'] .= 'User Email Address: ';
$mail['body'] .= $user_email;
// set mail property with changed value(s)
$contact_form->set_properties( array( 'mail' => $mail ) );
endif;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Optimum Creative |
