Hi!
We have a form that’s been used for years, and now we would like to have the added capability of attaching an image. (So a consumer can send us an image that might help with their problem.) Currently, a “confirmation” email is sent to the consumer with all of the info they gave us; a copy of the same information also goes to us. We would like the consumer’s image to be saved onto our server, so when we look at the completed form, the “Image:” line has a link to that page.
I.e. a consumer attaches an image named “picture.jpg”. The copy of the information we get would have a line that reads: “Image: http://www.example.com/test/uploads/picture.jpg”. I’m assuming I would use a variable to get the image name to display in order to complete the link. I’m lost about which variable I would use… but that might be because I can’t get the image to even save in the folder (I think) it’s supposed to. Obviously there’s something messed up, but I am lost as to what that is. Any help would be greatly appreciated!
The field to attach the image on the form:
[php]If you have an image that would help us assist you, please attach it here.
[/php]
The process file:
[php]<?php
//Collect contact form data
//Check Special Field
//Email ASC & Webmaster
//Email Sender
//Redirect to thank you page
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');
/******** CONTACT DATA **********/
$name = stripslashes($_POST['name']);
$company = stripslashes($_POST['company']);
$address = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$state = stripslashes($_POST['state']);
$zipcode = stripslashes($_POST['zipcode']);
$country = stripslashes($_POST['country']);
$website = $_POST['website'];
$phone = stripslashes($_POST['phone']);
$fax = stripslashes($_POST['fax']);
$email = stripslashes($_POST['contact']);
$Referred = stripslashes($_POST['referred']);
$CustomerType = stripslashes($_POST['CustomerType']);
$Comments = stripslashes($_POST['comments']);
$ConsumerHelp = stripslashes($_POST['ConsumerHelp']);
$UPC = stripslashes($_POST['UPC']);
$Describe = stripslashes($_POST['Describe']);
$uploaded_file = ($_FILES['uploaded_file']);
/******** CHECK SPECIAL FIELD **********/
$spamcheck = stripslashes($_POST['email']);
//if spamcheck isnt blank exit page, no need for error message to user, as its a spam bot
if ($spamcheck!=="") {
exit;
}
/******** EMAIL ASC & WEBMASTER **********/
$message = "
-----------------------------------------------------------------------------
Information Inquiry
-----------------------------------------------------------------------------
$name has visited the web site and would like some information.
The details they entered on the website are:
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
I need help with: $ConsumerHelp
UPC code or Item #: $UPC
What I am looking for: $Describe
Image: $uploaded_file
Kind Regards,
";
$email_address = "example@example";
$subject = "Information Inquiry";
$headers = "From: $name <$email>";
$message = str_replace("\r",'',$message); //fixes postfix php bug that double spaces messages
/******** EMAIL SENDER **********/
$message2 = "
-----------------------------------------------------------------------------
Re: Information Inquiry
-----------------------------------------------------------------------------
Thank you $name for visiting the web site. We will be using the details you entered to contact you.
Name: $name
Company: $company
Address: $address
City: $city
State: $state
Zip Code: $zipcode
Country: $country
Website: $website
Phone: $phone
Fax: $fax
Email: $email
Referred to web site: $Referred
CustomerType: $CustomerType
Comments: $Comments
I need help with: $ConsumerHelp
UPC code or Item #: $UPC
What I am looking for: $Describe
Kind Regards,
";
$email_address2 = "$email";
$subject2 = "Re: Information Inquiry";
$headers2 = "From: <[email protected]>";
$message2 = str_replace("\r",'',$message2); //fixes postfix php bug that double spaces messages
//send message 1 and save result in success var (either true for success, or false for fail
$success = mail($email_address, $subject, $message, $headers);
//conditionally send message2, no need to check success on this one
if (strpos($email,'@aol.com') == false) {
mail($email_address2, $subject2, $message2, $headers2);
}
if (!$success) {
// What happens when the form does not validate
header("Location: sorry.php");
die ();
} else {
// Your code here to handle a successful verification
header("Location: thanks.php");
$success;
}
?>
<?php $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["uploaded_file"]["name"]); $extension = end($temp); if ((($_FILES["uploaded_file"]["type"] == "image/gif") || ($_FILES["uploaded_file"]["type"] == "image/jpeg") || ($_FILES["uploaded_file"]["type"] == "image/jpg") || ($_FILES["uploaded_file"]["type"] == "image/pjpeg") || ($_FILES["uploaded_file"]["type"] == "image/x-png") || ($_FILES["uploaded_file"]["type"] == "image/png")) && ($_FILES["uploaded_file"]["size"] < 20000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["uploaded_file"]["error"] . ""; } else { echo "Upload: " . $_FILES["uploaded_file"]["name"] . "
"; echo "Type: " . $_FILES["uploaded_file"]["type"] . "
"; echo "Size: " . ($_FILES["uploaded_file"]["size"] / 1024) . " kB
"; echo "Temp file: " . $_FILES["uploaded_file"]["tmp_name"] . "
"; if (file_exists("upload/" . $_FILES["uploaded_file"]["name"])) { echo $_FILES["uploaded_file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "upload/" . $_FILES["uploaded_file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> [/php]