Jump to content

Email Notification Of Download


Phartog
 Share

Recommended Posts

Hello everybody,I want to get an email notification when somebody downloads a file on my website. I want an email with in this email a subject, what is downloaded (I have about 3 files that can be downloaded) and when it was downloaded. I am not so familiar with php, so please can someone help. I don't think you need the website, but here it is: www.patrickhartog.comAlready thanks

Link to comment
Share on other sites

You need a PHP script to handle the downloads, so instead of linking directly to a file like this:<a href="file.ext">download</a>You would link to a PHP script and tell it which file you want:<a href="download.php?file=file.ext">download</a>The download.php file would send the email and then redirect to the file. Go through the PHP tutorials, there's information about how to get the filename (you would use $_GET), how to send mail using the mail function, and to redirect you just send a location header:header('Location: file.ext');

Link to comment
Share on other sites

Thanks for the information. I already had a download.php. This was already working. Now I only want the mail function in it. This is what I have now in my download.php I am really new to php, so what do I do now???

<?$file = $_GET['file'];header ("Content-type:application/pdf");header ("Content-disposition: attachment; filename=".$file.";");header("Content-Length: ".filesize($file));readfile($file);exit;$to = "myemail@mail.com";$subject = "File download";$message = "There is a file downloaded from your website.";$from = "mymail@mail.com";$headers = "From: $from";mail($to,$subject,$message,$headers,$file);echo "Mail Sent.";?>

Edited by Phartog
Link to comment
Share on other sites

I found the solution, this is the code I used:

<?$file = $_GET['file'];header ("Content-type:application/pdf");header ("Content-disposition: attachment; filename=".$file.";");header("Content-Length: ".filesize($file));readfile($file);$to = "mail@mail.com";$subject = "A file is downloaded";$message = "Somebody downloaded $file of your website.";$from = "mail@mail.com";$headers = "From: $from";mail($to,$subject,$message,$headers);echo "Mail Sent.";exit;?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...