Reply LinkBack Thread Tools Search this Thread
Old 21-09-2006, 09:45   #1 (permalink)
captain caveman
Registered User
 
Join Date: Jun 2006
Posts: 44
Sending PHP email when link clicked

Another little php question...

I know how to send an email via php, however I would like to know how I can go about getting an email sent to me when a user clicks a particular download link on a website to tell me what files have been downloaded and roughly when.

Any help much appreciated.
  Reply With Quote
Old 21-09-2006, 09:59   #2 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 836
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
You'd need to set up some form of redirection script that does the following:

1) Pulls in the filename of the download that the user is requesting
2) Sends out an e-mail with the filename and time/date stamp
3) Redirects the user to the physical file so they can download it

For example, your link may look something like:

download.php?file=siteTemplate.zip

I'm sure there are plenty of free scripts that do this available at places such as hotscripts.com. Or if you wanted to do it yourself then it shouldn't be too hard. Just look in to sending e-mail via PHP and then issue the redirect() header.

- Mike
  Reply With Quote
Old 21-09-2006, 10:12   #3 (permalink)
captain caveman
Registered User
 
Join Date: Jun 2006
Posts: 44
I had considered redirecting and using a query string as you suggest, but as there will be a list of download links I don't really want to move away from that page. Currently when the link is clicked, the download (open/save etc) box appears straight away and the download page remains in the background. My idea was to simply get it to fire off an email at the same time.

Although... having said that, could I redirect back to the same page and process the query string with a php script which sends out the email and starts the download process?
  Reply With Quote
Old 21-09-2006, 10:15   #4 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 836
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Quote:
Originally Posted by captain caveman
I had considered redirecting and using a query string as you suggest, but as there will be a list of download links I don't really want to move away from that page. Currently when the link is clicked, the download (open/save etc) box appears straight away and the download page remains in the background. My idea was to simply get it to fire off an email at the same time.

Although... having said that, could I redirect back to the same page and process the query string with a php script which sends out the email and starts the download process?
As long as you are not printing any content to the screen and are issuing the redirect() straight to the download file, the user will not leave the original 'download' page. Their prompt will open straight away from that page. The e-mail sending and redirection is pretty much transparent to the user.

- Mike
  Reply With Quote
Old 21-09-2006, 10:22   #5 (permalink)
captain caveman
Registered User
 
Join Date: Jun 2006
Posts: 44
Ok, sounds good, thanks Mike.

So (forgive my ignorance), whereabouts would I place the php script and how would I get it to trigger once the link has been clicked?
  Reply With Quote
Old 21-09-2006, 10:50   #6 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 836
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Quote:
Originally Posted by captain caveman
Ok, sounds good, thanks Mike.

So (forgive my ignorance), whereabouts would I place the php script and how would I get it to trigger once the link has been clicked?
Basically, once you've written the download script all you need to do is replace the links in your download page to point to the php script instead of the direct files but send the download path as a variable to the php script (as outlined in a post above).

So if you download link is "/downloads/someData.zip" you would change it to "download.php?file=/downloads/someData.zip" where the "file" variable is now telling the php script where to send the user in the redirect() after the e-mail has been sent.

- Mike
  Reply With Quote
Old 21-09-2006, 11:04   #7 (permalink)
captain caveman
Registered User
 
Join Date: Jun 2006
Posts: 44
Ah got ya, thanks very much Mike I'll give it a try. Probably be back at some point!
  Reply With Quote
Old 21-09-2006, 11:06   #8 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 836
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Quote:
Originally Posted by captain caveman
Ah got ya, thanks very much Mike I'll give it a try. Probably be back at some point!
No worries
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8