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("your.email@somewhere.com", "Download Notification: ".$package_data->post_title, $message, $headers);
6 Comments
Have done and is now working. Thank you.
Do I need to purchase the Download Notification Add On?
Yes, download notification will do the job.
Thank you for responding.
Sadly, it doesn’t work as it is causing an HTTP 500 Error. I am placing the code into the functions.php file.
Hi. I’ve tried to implement this but it isn’t working.
function download_notification($package){
$package_data = get_post($package[‘ID’]);
$headers = ‘From: Vanguard Healthcare Website ‘ . “\r\n”;
$headers .= ‘Content-type: text/html’ . “\r\n”;
$message = “Downloader’s IP: “. $_SERVER[‘REMOTE_ADDR’];
wp_mail(“jvmiller@gmail.com”, “Download Notification: “.$package_data->post_title, $message, $headers);
}
add_action(“before_download”, “download_notification”);
Any help would be appreciated.
J
Please use this:
https://www.wpdownloadmanager.com/doc/action-reference/wpdm_onstart_download/