PHP Email Form With Attachment

I have searched high and low for a php email script that will allow me to upload an attachment via the webpage and email all the info to the specified recipient. It took digging endless hours on Google to piece one together. I have no idea who wrote the script as I found it on a forum and modified it for my own liking. Anyway, here’s a short tutorial on how to use it.


Download: PHP Email Form

  1. Download the script and unzip the contents.
  2. Open the uploader.php file. Scroll to the bottom and you will see a place to enter in the desired email address to which you want the contents emailed.
  3. Open form.php and copy the contents into your desired php file (This will pull in the form from the uploader.php file).
  4. Be sure to put a file include at the top of your working php document to include the uploader.php. If you are unsure how to do that, check out this article.
  5. Upload both files to your server and try it out. Leave a comment if you need help.

**Edit** Sorry but I lost these files when I switched servers. If I find another, I’ll be sure to update this page.

20 Comments

ErikCG said...

Hi,
I’ve tried the form and it’s working, but i cannot make the Message text area work.
I recive the mails, and the attached files, but no the message.

Could you help me?

Thanks!!

Erik

Jayme said...

Can you send me a link to your website to: jaymeblackmon at gmail.com, so I can take a look at it? Thanks.

Lars said...

Hi there!

I have the same problem.. I can read the text if I have a look at the original MIME code, but not displayed as a part of the email.. I think there is a problem with the separations of the MIME email.
Please let me know if you find out what`s the issue.. I had trouble.. ;)

Cheers,

Lars

Jayme said...

Hi Lars,

Yeah it’s strange because I was able to use it on one of my servers, but I uploaded it to another server and it didn’t work. I can assure you I’m not a php guru by any means. I think Erik was going to ask a programmer he knows about it. He said if he can find out an answer, he’ll post it and let me know. Feel free to post the script elsewhere if you can find a resolution for it and I’ll update my copy of the script here. Thanks and sorry about that!

ErikCG said...

I’ve tried the script on the final server of the website (my server was only for the tests and design) and the script is working at all.

My friend says that maybe it’s the version of the php in each server. Could be that?

Cheers!

Lars said...

Ah, thanks to both of you for replying. :) So Erik, everything is working on the final server?
Might be the php version or a setting in php.ini or something, I do however wonder if it can`t have anything to do with the MIME layout of the email being sent out, as I can read the body text when I view the MIME source received in my inbox.

Would really appreciate it if any of you discover something,
thanks again, I am not a php guru either. ;)

Lars.

virgil said...

Hi,

I tried to change some thing in the script, such as multiple attachments, but It didn’t work.

Could you tell me how I could change the script to get this.

thanks

virgil

SKI said...

Thanks for the uploading script, it was nice and simple to use although it required a few tweaks.

A few things to check:

Make sure your php code starts with a “” tag and put the “” inside the form not outside. (This won’t stop it working on Firefox).

Be careful of not checking email addresses properly, particularly when you use the “To:” field in the headers, see this article:

http://www.securephpwiki.com/index.php/Email_Injection

Read the above article again and work out why it could be really bad to mix the “To:” header with a file attachment script ;\

Check your $_FILES array more carefully - you can look at the “mimetype” in $_FILES['attachment']['type'] and compare it to allowed values. Check here for mime types:

http://www.webmaster-toolkit.com/mime-types.shtml

If you want to upload more than one file:

Then in php - $_FILES['userfile']['name'][0] and $_FILES['userfile']['name'][1] will contain the names respectively

http://php.net/manual/en/features.file-upload.multiple.php

Watch out for your “multipart” type: The following article suggests using “multipart/mixed” for sending attachments:

http://www.sitepoint.com/print/advanced-email-php

Later.

SKI

Triqui said...

Nice script, seems to work.
I am going to fit it to my needs, then I’ll show you final result.

Thank you.

Ryan Gallion said...

Hey, thanks for the code, works great…except for the message problem that others are having.

If I send the email to my work account, the message displays, btu if I send it to a gmail account, it doesn’t…

Has anyone figured this out?

mike said...

tried to add part of your code to existing simple form. Wanted to do attachments but doesn’t seem to work. Can you look at it and tell me where I am wrong?

” . $headersep . “Reply-To: \”$name\” ” . $headersep . “X-Mailer: chfeedback.php 2.07″ );

header( “Location: $thankyouurl” );
exit ;

?>

Brett Meyer said...

I’ve working all afternoon trying to get a solution up and running. Thanks for finally solving the problem!!!

Dan said...

Id like to take a look at the script (this could save me a lot of time) but the link to the zip file is not working. Any chance you could email me the script? Or let me know when the link is working again.

Thanks!

Lee said...

Can you email me a copy of the script please? The link is broken.

Many thanks!

Jayme said...

Hey folks, sorry I must have deleted the zip by accident when I moved everything over to Dreamhost. You might be able to get Brett Meyer at http://www.electrovation.com/ to send you the script. I think he downloaded it here according to his comment above. If you happen to get it, email it to me: jaymeblackmon@gmail.com

K-OS said...

Hi Just wondering if you got another copy of this script… I have been hunting for something for months…. thanks for any help.

rob said...

I’ve been looking for a script like this for a long time but alas I can’t find one! If you find your script please send it over to me.

James Lewis said...

Hi, if anyone has a copy of the email + attachment script I would be most grateful.
Thanks in advance

Eamonn said...

Hi there, been looking everywhere for a php mail form with an attachment field to it - the download link unfortunately is not working any chance you can email it to me?

Many thanks

Eamonn

David said...

Hi, can you email me a copy when you mange to find it, thanks.