Is there a way to have an email sent to me when a user downloads a file?

I have some downloads that I would like an email to be sent to me when a user downloads particular files. The email sent to me would notify me of the user's name and/or email address.

BTW: I would have posted this under "plugins" but I am unable to select a plugin from the drop down when asked, and the form won't go through without. This happens in both Safari and Chrome. I'm on a Mac.

  • Arizona Girl
    • The Crimson Coder

    I got this below code from the WP Download Manager site.

    Does anyone know how to change some of the variables here so that it gives met the user's name and email? Right now it only provides me an IP address.

    -----------------

    function download_notification($package){
    $package_data = get_post($package['ID']);
    $headers = ‘From: Site Name ‘ . “\r\n”;
    $headers .= ‘Content-type: text/html’ . “\r\n”;
    $message = “Downloader’s IP: “. $_SERVER['REMOTE_ADDR'];
    wp_mail(get_option(“admin_email”), “Download Notification: “.$package_data->post_title, $message, $headers);
    }

    add_action(“before_download”, “download_notification”);

  • Hoang Ngo
    • Code Slayer

    Hi @Arizona Girl,

    I hope you are well today.
    About the code, you can modify like this, so the email will include the user name (only if user logged in)
    `function download_notification( $package ) {
    $package_data = get_post( $package['ID'] );
    $headers = 'From: Site Name ' . "\r\n";
    $headers .= 'Content-type: text/html' . "\r\n";
    $message = "Downloader's IP: " . $_SERVER['REMOTE_ADDR'] . "\r\n";
    if ( is_user_logged_in() ) {
    global $current_user;
    get_currentuserinfo();
    $message .= 'Downloader username: ' . $current_user->user_login;
    }
    wp_mail( get_option( "admin_email" ), "Download Notification: " . $package_data->post_title, $message, $headers );
    }`

    If you have any issues please don't hesitate to let us know so we can assist

    Best Regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.