Send e-Mail Notification When Someone Downloads

Some users  asked me how to Add Mail Notification When Someone Downloads and actually it is pretty easy. WordPress Download Manager has an action hook “before_download” , if you attach any function with that hook and write email notification code inside the functional that will work perfectly. Here is the example code:

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"); 

Simply add the above code block at the end of your theme functions.php. Here get_option("admin_email") will take the site admin email address, but you can replace it with any email address like wp_mail("", "Download Notification: ".$package_data->post_title, $message, $headers);

Comments [ 6 ]

Leave a Reply