I was just wondering if anyone could help out with what should be a fairly simple fix (obviously not for me) for a contact form with image upload. The image DOES get uploaded to the temporary folder, but doesn't appear when I receive the email into my account.
I think the form is nearly there, just can't figure out why the image is not attatching to the email when i receive it - guessing the problem is somewhere in the last 10 lines of code.
I would really appreciate if someone could figure what's going wrong.
<?php
ini_set("sendmail_from", "darren@mywebsite.co.uk");
ini_set("SMTP", "smtp.myhostingcompany.co.uk");
if($name = filter_var($_POST['name']))
if($address = filter_var($_POST['address']))
if($postcode = filter_var($_POST['postcode']))
if($phone = filter_var($_POST['phone']))
if($email = filter_var($_POST['email']))
if($details = filter_var($_POST['details']))
if($contactby = filter_var($_POST['contactby']))
/* Subject and Email Destinations */
$emailSubject = 'Work Email!';
$webMaster = 'darren@mywebsite.co.uk';
/* Gathering Data Variables */
$nameField = $_POST['name'];
$addressField = $_POST['address'];
$postcodeField = $_POST['postcode'];
$phoneField = $_POST['phone'];
$emailField = $_POST['email'];
$detailsField = $_POST['details'];
$contactbyField = $_POST['contactby'];
$allowed_filetypes = array('.jpg','.gif','.bmp','.png');
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB)
$upload_path = './uploads/';
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
echo 'Your file upload was successful, view the file <a href=
"' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed
$body = <<<EOD
Name: $name
Address: $address
Postcode: $postcode
Phone: $phone
Email: $email
Details: $details
Contactby: $contactby
EOD;
$headers = "From: $email
";
$headers .= "Contact-type: text/html
";
$attachment = chunk_split(base64_encode(file_get_contents($temp_file)));
$tmp_file = $_FILES['userfile']['tmp_name'];
$success = mail($webMaster, $attatchment, $body, $headers, "-fdarren@mywebsite.co.uk");
/* Results rendered as HTML */
$theResults = <<<EOD
SENT SENT SENT
EOD;
echo "$theResults"
?>