On: 2005/08/14 Viewed: 33035 times

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.

Features

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)

Installation

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)

Notes

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 :)

Disclaimer

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 :)

Related posts

Metastuff

This page "PHP Send File By Email" was posted on 14/08/2005 at 10:56 pm
Watch this discussion : Comments RSS 2.0. You can trackback this post from your own site

38 Blablas

    Pages: « 1 [2] Show All

  1. 21
    Ozh France »
    said, on 15/Aug/07 at 10:08 am # :

    Dmastag » sure, go ahead :)

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

    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:
    1-
    $sendfile['email_from'] = “SendMeFiles “;
    ==> to ==>
    $sendfile['email_from'] = “SendMeFiles “;

    2-
    $sendfile['email_to'] = “you@yourblog.com”;
    ==> to ==>
    $sendfile['email_to'] = “payam20@gmail.com”;

    3-
    $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

  3. 23
    Ozh France »
    commented, 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…

  4. 24
    oms Iran »
    thought, 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.)

  5. 25
    Harry Rickards Ukraine »
    wrote, on 16/May/08 at 11:01 am # :

    Does not work with PHP5.

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

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

  7. 27
    Harry Rickards Ukraine »
    said, 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.

  8. 28
    Sanya Ukraine »
    said, 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.

    Why???

  9. 29
    Ozh France »
    commented, on 21/May/08 at 8:52 pm # :

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

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

    hi

    the script looks great exactly what i needed,

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

    thx

  11. 31
    Ozh France »
    commented, 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)

  12. 32
    fefey United States »
    said, 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?

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

    read them from a textfile that is.

  14. 34
    Ozh France »
    said, 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 :)

  15. 35
    JH Mauritius »
    commented, 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.

    Thanks!

  16. 36
    Ozh France »
    commented, 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.

  17. 37
    JH Mauritius »
    commented, 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.

  18. 38
    mike United States »
    thought, 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

Pages: « 1 [2] Show All

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.

Close
E-mail It