Warning: Creating default object from empty value in /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php on line 31

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php on line 73

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php on line 73

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/ozh-who-sees-ads/wp_ozh_whoseesads.php on line 630

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/ozh-who-sees-ads/wp_ozh_whoseesads.php on line 631

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/themes/planetozh/functions.php on line 172

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/themes/planetozh/functions.php on line 173
PHP Send File By Email « planetOzh
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. 1
    Pastor United States »
    thought, on 23/Aug/05 at 8:50 am # :

    where iss the software?

  2. 2
    Ozh France »
    wrote, on 23/Aug/05 at 12:29 pm # :

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

  3. 3
    Mark United States »
    wrote, on 30/Aug/05 at 6:02 pm # :

    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. 4
    Ozh France »
    commented, on 30/Aug/05 at 8:44 pm # :

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

  5. 5
    webmaster Netherlands »
    replied, on 04/Oct/05 at 3:39 pm # :

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

  6. 6
    Ozh France »
    commented, on 04/Oct/05 at 5:35 pm # :

    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. 7
    webmaster Netherlands »
    replied, on 05/Oct/05 at 12:09 am # :

    Indeed, great, works fine! Thanks very much.

  8. 8
    Van Nguyen Australia »
    thought, on 26/Nov/05 at 1:05 pm # :

    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. 9
    Ozh France »
    thought, on 26/Nov/05 at 5:28 pm # :

    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. 10
    Van Nguyen Australia »
    commented, on 26/Nov/05 at 11:44 pm # :

    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. 11
    Bionic Latvia »
    wrote, on 08/Dec/05 at 7:33 am # :

    where is the script??? :P

  12. 12
    Ozh France »
    wrote, on 08/Dec/05 at 9:23 am # :

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

  13. 13
    Ozh France »
    wrote, on 21/Dec/05 at 9:50 pm # :

    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. 14
    khyrel Malaysia »
    thought, on 07/Jun/06 at 5:04 pm # :

    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. 15
    Ozh France »
    replied, on 07/Jun/06 at 9:21 pm # :

    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. 16
    galdrusa Spain »
    said, on 21/Aug/06 at 2:10 pm # :

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

  17. 17
    cwimie Indonesia »
    wrote, on 27/Aug/06 at 7:48 am # :

    its work!!! thx!

  18. 18
    nice Indonesia »
    commented, on 11/Sep/06 at 12:01 pm # :

    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. 19
    Ben United Kingdom »
    wrote, on 01/Jan/07 at 9:06 pm # :

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

  20. 20
    Dmastag Indonesia »
    wrote, on 15/Aug/07 at 8:24 am # :

    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. 21
    Ozh France »
    wrote, on 15/Aug/07 at 10:08 am # :

    Dmastag » sure, go ahead :)

  22. 22
    Payam Rezaie.M Iran »
    commented, on 13/Apr/08 at 8:53 pm # :

    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. 23
    Ozh France »
    said, on 13/Apr/08 at 9:23 pm # :

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

  24. 24
    oms Iran »
    commented, on 12/May/08 at 4:15 pm # :

    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. 25
    Harry Rickards United Kingdom »
    thought, on 16/May/08 at 11:01 am # :

    Does not work with PHP5.

  26. 26
    Ozh France »
    commented, on 16/May/08 at 11:17 am # :

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

  27. 27
    Harry Rickards United Kingdom »
    wrote, on 16/May/08 at 11:23 am # :

    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. 28
    Sanya Ukraine »
    replied, on 21/May/08 at 5:13 pm # :

    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. 29
    Ozh France »
    wrote, on 21/May/08 at 8:52 pm # :

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

  30. 30
    Dee Israel »
    said, on 24/May/08 at 11:19 am # :


    the script looks great exactly what i needed,

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


  31. 31
    Ozh France »
    thought, on 25/May/08 at 7:34 pm # :

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

  32. 32
    fefey United States »
    thought, on 14/Jun/08 at 5:53 pm # :

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

  33. 33
    fefey United States »
    thought, on 14/Jun/08 at 5:54 pm # :

    read them from a textfile that is.

  34. 34
    Ozh France »
    replied, on 14/Jun/08 at 6:40 pm # :

    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. 35
    JH Mauritius »
    said, on 01/Jul/08 at 8:27 pm # :

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


  36. 36
    Ozh France »
    thought, on 01/Jul/08 at 9:49 pm # :

    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. 37
    JH Mauritius »
    thought, on 02/Jul/08 at 5:22 am # :

    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. 38
    mike United States »
    said, on 20/Jul/08 at 8:47 pm # :

    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. 39
    Greg United States »
    said, on 16/Aug/08 at 3:58 am # :

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

  40. 40
    Yaz United States »
    wrote, on 26/Aug/08 at 8:46 pm # :

    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. 41
    Hank United States »
    thought, on 26/Aug/09 at 5:46 pm # :

    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. 42
    drew United States »
    thought, on 11/Dec/10 at 5:23 pm # :

    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. 43
    Mike Flynn United States »
    said, on 10/Feb/11 at 6:47 am # :

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

  44. 44
    Mike Flynn United States »
    thought, on 10/Feb/11 at 7:31 am # :

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

  45. 45
    Asikul islam Bangladesh »
    wrote, on 07/May/13 at 9:04 pm # :

    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. 46
    Ozh France »
    thought, on 07/May/13 at 10:12 pm # :

    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. 47
    Frank United States »
    replied, on 10/May/13 at 9:32 pm # :

    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. 48
    Ozh »
    thought, on 11/May/13 at 11:20 am # :

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

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.