Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Php WP how to send a mail to the admin from a logged user

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 439
    Answer it

    Hello, I would like to know if in WP PHP is possible to make something like that: I need for the logged user a form which when compiled and submitted, send a mail to the admin with the all data of the user from db and the message he/she write. In this way the logged user has to not write the mail because will be send from the db with the all other info. Please let me know with examples or where to see in internet some solution for my problem Thank you Jakub

 1 Answer(s)

  • To retrieve data of logged-in user & send all the data to admin with user message.

    a. Get user data of logged-in user.

    global $current_user;
    get_currentuserinfo();
    
    $message = 'Username: ' . $current_user->user_login . "\n";
    $message .= 'User email: ' . $current_user->user_email . "\n";
    $message .= 'User level: ' . $current_user->user_level . "\n";
    $message .= 'User first name: ' . $current_user->user_firstname . "\n";
    $message .= 'User last name: ' . $current_user->user_lastname . "\n";
    $message .= 'User display name: ' . $current_user->display_name . "\n";
    $message .= 'User ID: ' . $current_user->ID . "\n";
    $message .= $_POST['name_of_text_area'];
    

    b. Retrieve the e-mail of the administrator.

    $admin_email = get_option( 'admin_email' );

    c. Send email to admin

    wp_mail( $admin_email, 'Subject', $message );

    Please let me know if you need anything else.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: