On: 2005/08/14 Viewed: 72074 times
Shorter URL for this page: http://ozh.in/l8

Sometimes, you find some interesting files on the internet, and want them mail to you, your office, or a friend. Or it's just that your corporate proxy won't let you access a file you want.

Why bother sending it yourself with your mail client and your connection when your webserver and its fat dedicated line can do it for you ?

PHP Send File By Email is a script that you feed with a file URL — http://somewhere.com/somefile.zip — and that gets this file delivered into an email box, as a regular attachment.


The script is pretty simple. Nothing fancy, just doing what it's supposed to do.

  • Mirrors on your webserver the remote file, then sends it by email as an attachment
  • Files can be binary (exe, zip, images, …) or text (txt, html, uncompiled code …)
  • Locally mirrored files can be deleted after they've been sent, or kept on your server for future use
  • Simple and clean interface (see demo)


Download the file and edit the few lines at the beginning to suit your needs.

  • sendfile.php (colorized html, copy & paste into a blank file but don’t download it : it’s colorized html, not code :)
  • sendfile.txt (right click & save as .php)

Upload the script anywhere on your webserver, and create a directory according to what you specified when editing the script. Make sure this directory is readable and writeable by this PHP script (i.e. chmod 777)


The script needs PHP function fopen() to be enabled on your webserver (this is probably the case).

If the requested file is too big, sending it by email can fail, depending on the recipient mail server. As an example, GMail accounts bounce back files that are bigger than 10 MB.

If your webserver's or the file's server's connection is too slow, the script can exceed its maximum execution time (i.e. timeout, which is set at 30 seconds on most web servers). If this happens, you need to either switch to a decent host, a find a faster mirror for the file you are requesting :)


Prices, Specs, Availability, Terms, and Specials are subject to change without notice. Not responsible for inadvertent or typographical errors. Acceptance of the Terms of Use and Acceptable Use Policy is a condition of use. Please read all instructions and warnings before use. Must be 18 years of age or older to proceed further. Children under the age of 18 should have the consent of a parent before using. Use at your own risk. Any resemblance to persons living or dead is purely coincidental. No animal or computer harmed. Not my prettiest code. But it works :)

Shorter URL

Want to share or tweet this page? Please use this short URL: http://ozh.in/l8


This page "PHP Send File By Email" was posted on 14/08/2005 at 10:56 pm
Watch this discussion : Comments RSS 2.0.

48 Blablas

  1. Pastor says:

    where iss the software?

  2. Ozh says:

    Oô …
    What is your question exactly, dude ? :Þ

  3. Mark says:

    I get an error when I click to download that file. it seems to be protected and not allowing me to download it. any ideas what the problem is?

  4. Ozh says:

    There's nothing special with it. It must be a problem either with your browser or, more likely, a firewall or proxy.

  5. webmaster says:

    Thank yo so much for this script!
    Is there any way to change this script to make it work in javascript disabled browsers?

  6. Ozh says:

    For the javascript impaired :
    Find the line with "//print '<input type="submit">';" and uncomment it. Then, 3 lines below, comment out the javascript one liner. That's all.

  7. webmaster says:

    Indeed, great, works fine! Thanks very much.

  8. Van Nguyen says:

    it keeps on saying 3 seconds execution exeeded after 100MB has been fetched, is there a way to bypass it, or is there a way to resume the fetching after the file has been broken, thanx

  9. Ozh says:

    Van Nguyen » this looks like a server configuration problem with a maximum time of 3 seconds for PHP scripts to execute ? Wow. That's the lowest I've ever seen. Tell your host they suck :P
    In other words, nothing I can help you with, sorry. You can process files as long as it takes less than 3 seconds to mirror and another 3 seconds to send.

  10. Van Nguyen says:

    Normally my other hosts its 30 seconds, but this one has 300GB bandwidth, but only 3 seconds…Anyways, can you add a resume feature for those like me with 3 seconds execution :( That would be great :)

  11. Bionic says:

    where is the script??? :P

  12. Ozh says:

    Hidden behind a "download" link, where about 1500 people before you actually managed to find it.

  13. Ozh says:

    To the dude whose comments I've accidently deleted : sorry dude :) And about your problem : I don't know. My own install of this script works fine with .mp3 or any extension. This is either a problem on your server, or a problem with hotmail. So I'm afraid I can't be of any help. BTW if you want a Gmail invite and drop your hotmail, feel free to send me an email (ozh at planetozh dot com)

  14. khyrel says:

    how can i use this as via-email download manager? i mean, i want to distribute document file to people who request for it. the document file already on the server and i just want it to be sent to requesting persons via email. can this be done? would you mind to guide me how to do it?

    thanks a bunch!

  15. Ozh says:

    khyrel » install the script and tell your friends where it's located so that they can use it to have files sent to them. Or send me a mail with your special requirements (the way you would like it to work) and the budget you're willing to spend for a customization to suit your needs :)

  16. galdrusa says:

    Could I use this script for sending a file that is in my hard disk?

  17. cwimie says:

    its work!!! thx!

  18. nice says:

    There is error message "Allowed memory size of 16777216 bytes exhausted" when send file approx 15MiB or bigger, can it set not to use to much memory hog ?

  19. Ben says:

    How can I use this to send a file from my hard disk?

  20. Dmastag says:

    This is a pretty sweet script you've done there. I actually have thought to rewrite it, so it would be able to download Updates (like Norton Anti Virus) periodocally using Cron Jobs. It's just a thought. You don't have a problem with that, don't u ?

  21. Ozh says:

    Dmastag » sure, go ahead :)

  22. Hi
    First excuse me for my bad or mistake english sentences,because it is not my language…
    Then; I have a problem in using this script(sendfile).
    after saving that script to my pc,i open it by notepad,then edit the parameters below:
    $sendfile['email_from'] = "SendMeFiles ";
    ==> to ==>
    $sendfile['email_from'] = "SendMeFiles ";

    $sendfile['email_to'] = "you@yourblog.com";
    ==> to ==>
    $sendfile['email_to'] = "payam20@gmail.com";

    $sendfile['file_dir'] = "/home/user/you/sendfile/files";
    ==> to ==>
    $sendfile['file_dir'] = "/home/asisir/public_html/2";

    i create a directory with name "2" in public_html directory & give it 777 premision and copy this script that saved with .php extention and index name,on it.

    when i go to that address (www.asis.ir/2) with IE,an error apear with title: 500 Internal Server Error
    before i change the premission of directory "2",this url direct me to sendfile script page,but after it,not.

    can you help me to solving this problem?

    Thank you
    Payam Rezaie.M

  23. Ozh says:

    Payam Rezaie.M » Don't know, it could be anything with your server. I can't help, sorry…

  24. oms says:

    Thanks alot, I really needed "PHP send mail".
    I think mirroring is not needed when sending a file on the same host.
    If I am true would you change a piece of your code to add option of Mirroring local files.
    Its very helpful when some host admins do not allow write access.
    (sorry that I do not know php, to help making changes.)

  25. Does not work with PHP5.

  26. Ozh says:

    Harry Rickards » I'm running it here on this blog with PHP 5.2.3

  27. Oh. On mine it comes up with an error. But I've found a similar script that works, but isn't as good as yours sounds.

  28. Sanya says:

    Mirroring file http://download.qip.ru/qip8060.exe

    File locally mirrored !

    Preparing mail and attachment …

    Sending file to 123@ya.ru

    ERROR : could not send email.

    File successfully deleted.


  29. Ozh says:

    Sanya » Dont know and could be anything: server config, file too large for sending, etc…

  30. Dee says:


    the script looks great exactly what i needed,

    do you have a read me installation file cause im not sure how configure it


  31. Ozh says:

    Dee » There is nothing to configure except a few self-explanatory and non critical stuff at the beginning (default email, etc)

  32. fefey says:

    Is there a way of adding code to read multiple emails where you want to send the attachment to?

  33. fefey says:

    read them from a textfile that is.

  34. Ozh says:

    fefey » Yes, just fopen() the content of a textfile and use it as your recipient list. No, I'm not going to do it :)

  35. JH says:

    What's the file limit? I've been trying to upload a 450MB file and when it reaches 180MB, it stops uploading.


  36. Ozh says:

    JH » Depends on your server configuration. Then, no email server on earth will accept a 450 MB attachment. I think you didn't understand the purpose of this plugin.

  37. JH says:

    OZH, J'ai bien compris le plugin mais j'ai pu modifier le script pour que je puisse seulement télécharger des fichiers sur le server. J'en ai besoin que de cette option. Et le server host peut accepter des fichiers allant jusqu'à 1GO.

  38. mike says:

    I cant use this script. I keep getting this error everytime I try to access this.

    Fatal error: Cannot re-assign $this in /home/user/public_html/sendfile.php on line 230

  39. Greg says:

    I am also getting the $this fatal error with PHP 5. Ozh, can you tell us how you are getting it to work?

  40. Yaz says:

    I would like to send the path of a file on the local machine not a url nor the server. How can I modify the code to do this?

  41. Hank says:

    I tried several scripts found on various sites but none worked well. This one worked the first time – and it even provides a great user interface.


  42. drew says:

    I set this up to send ebooks straight to my Kindle via my free Kindle email address, however, the Amazon delivery services says it gets the email without any attachments. Tests to other addresses show that attachments are being sent. Any ideas?

  43. Mike Flynn says:

    it throws an error when sending vector files like .ai. Any recommendation there, besides adding scripting to compress into .zip first?

  44. Mike Flynn says:

    regarding my prev. comment, it works fine as long as I do not rename the file. Thanks!

  45. Asikul islam says:

    i want to send a file from your script but i get one error .
    i give you this error.please give me idea to solve this error.this error is….
    ERROR : couldn't read source file http://http://jobs365bd.com/jobprotal.zip

    Asikul Isalm roke

  46. Ozh says:

    Asikul islam » your server has either connectivity troubles with that particular URL, or is just configured to forbid use of some functions. Can't help.

  47. Frank says:

    Ozh, I get the message, "File successfully sent!", and the file is mirrored in the folder, but the file is never received in the email inbox. Do you know what is causing this? Thanks in advance!

  48. Ozh says:

    Frank » Can't know. Email server limitation because of file size, function disabled for "security", etc…

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.