Hi
This is my 1st post. I am in desperate help in working out the php for the html form with attachment.
I have send html forms before with php but i cant work out how to do it with the file attachement.
Any help would be really appreciated.
This is the HTML
<form action=“#” method=“post” enctype=“multipart/form-data” class=“contact-form” id=“contact-form”>
<fieldset class=“group”>
<p>
<input type=“text” title=“Your Name”>
</p>
<p>
<input type=“text” title=“Your E-mail”>
</p>
</fieldset>
<fieldset>
<p>
<textarea cols="30" rows="4" title="Skimage Title"></textarea>
</p>
</fieldset>
<p>
File to upload: <input type=file name=upfile></p>
<button type="submit">Submit</button>
</form>
Thanks Again
Patche
2
You can grab the file form by doing $file = $_FILE[‘upfile’]; . You will probably want to validate it too.
Do I just add that to the contact.php file
Im not sure what I am doing wrong but im getting everything but the attachment being sent through.
This is my html:
<form action=“contact.php” method=“post” enctype=“multipart/form-data” name=“contactform”>
<table width=“450px”>
<tr>
<td valign=“top”>
<label for=“name”>Name *</label>
</td>
<td valign=“top”>
<input type=“text” name=“name” maxlength=“50” size=“30”>
</td>
</tr>
<tr>
<td valign=“top”>
<label for=“email”>Email Address *</label>
</td>
<td valign=“top”>
<input type=“text” name=“email” maxlength=“80” size=“30”>
</td>
</tr>
<tr>
<td valign=“top”>
<label for=“enquiry”>Skimage Title.*</label>
</td>
<td valign=“top”>
<textarea name=“enquiry” maxlength=“1000” cols=“25” rows=“6”></textarea>
</td>
</tr><br>
<tr>
<td valign=“top”>
<label for=“upfile”>Filename:</label>
<input type=“file” name=“file” id=“file”><br>
</td>
</tr>
<tr>
<td colspan=“2” style=“text-align:center”>
<input type=“submit” value=“Submit”>
</td>
This is my Php:
<?php
$EmailFrom = $_REQUEST[‘email’];
$EmailTo = “hannah@muddypawswebdesign.co.uk”; //
$Subject = “Contact form”;
$Name = Trim(stripslashes($_POST[‘name’]));
$Email = Trim(stripslashes($_POST[‘email’]));
$Message = Trim(stripslashes($_POST[‘skimage_title’]));
$file = $_FILE[‘file’];
// validation
$validationOK=true;
if (!$validationOK) {
echo “Error”;
exit;
}
// prepare email body text
$Body = “”;
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Skimage_title: ";
$Body .= "
";
$Body .= "
";
$Body .= $Skimage_title;
$Body .= "
";
// send email
$success = mail($EmailTo, $Subject, $Body, “From: <$EmailFrom>”);
// redirect to success page
if ($success){
echo “Thankyou for your enquiry. We will be in touch very soon!”;
}
else{
echo “Error”;
}
?>
Drummin
5
You don’t have Content-Type: multipart/mixed headers in place. See this example.
http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script