Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

PHP Contact Form with file attachment

Has anyone made a contact form that will send file attachments through email? If so, can you share your source code?

5 Answers

Hey James,

You can find tons of tutorials online for setting up a contact form like this. I typed into Google "php contact form with file attachment" and found this link right away: http://www.sanwebe.com/2014/04/ajax-contact-form-attachment-jquery-php It seems solid enough. And there are quite a few more where that came from.


No problem, James, and I am not trying to sound rude at all but Google has access to a wealth of knowledge. Use it, my friend!

Yeah, I understand. I was just trying to figure it out on my own without using something someone else has created. What I created was working in plain text but the actual attachment wasn't coming through on the email side. I still appreciate this! Lol

You can use their code for ideas on how to create your own code. You can at least see how they are including the functionality to implement file attachments, and then adapt that code to your own code.

That's true. However the form I originally created was all php with php validations no javascript or ajax. I still ended up using the contact form that you sent me. I just changed the css to fit what I originally created.

You should definitely go with adding JavaScript validation to any kind of forms whenever possible. PHP should always be in the back end to validate, of course, but JavaScript validation gives that immediate response of "Hey you need to fix this" instead of having to wait for the data to be processed by the server and then sent back to tell you what's wrong. I do some easy JS validation with PHP in the back to validate it on my form: http://www.marcusparsons.com/contactme.php

Thanks for the advice! Never thought of it that way. Point well taken!

Anytime, man. Good luck on your future endeavors! =]