Click to See Complete Forum and Search --> : [RESOLVED] Attaching a file to a server-sent email


Wiz Creations
07-20-2006, 01:48 PM
I have the following form to allow a user to send me an email. It's continuous in the code for the page, but I separated it here so that it colors nicely. Is there a way to allow someone to attach a file with a maximum size of 6MB? If yes, what is the code for that?
Also, do you think it is a good idea to allow people to send files through a form like this? Thanks for the input.
<?php
if (isset($_POST['submit'])) {
mail("contact@wizcreations.com","form contact","NAME: ".$_POST['fname']." EMAIL: ".$_POST['email']." MESSAGE: ".$_POST['message']);
echo "Thank you for contacting Wiz Creations.\n";
} else {
?>
<form action="contact.php" method="post">
<table align="center" width="300" cellspacing="5" border="0">
<tr><td align="center">Your Name:<br><input name="fname" type="text" value="" size=35></td></tr>
<tr><td align="center">Your Email Address:<br><input name="email" type="text" value="" size=35></td></tr>
<tr><td align="center">Your Message:<br><textarea wrap="hard" name="message" rows=8 cols=35></textarea></td></tr>
<tr><td height="26" align=center><input type="submit" name="submit" value="Submit">&nbsp;&nbsp;<input type="reset" value="Reset"></td></tr>
</table>
</form>
<?php } ?>
Is that last <?php } ?> required?

NogDog
07-20-2006, 02:48 PM
What you ask is possible, but not so trivial that I have time to write the code. I would refer you to Bokeh's post on file uploads that is "stickied" at the top of this forum to get some idea on what is involved in sending a file from a web form to the server. As far as sending attachments to an email, I use the phpmailer class (http://phpmailer.sourceforge.net/) to handle things like that, so you might want to take a look at it.

That last <?php } ?> is probably required to close out an if block that was started earlier.

Wiz Creations
07-20-2006, 03:03 PM
Oh. I appologize. I didn't realize that was there. Thanks for the response.