Hi There i’m trying to allow my user to submit a form to send to me with a file attachemt. Everthing works great except the attachemt of the file.
Can anyone help me? here is my form code:
[code=php]
<form name=”form” enctype=”multipart/form-data” method=”post” action=”send-coments1.php”>
<?php
if ($error == 1)
{
echo “<p>Sorry, we were unable to process your registration.<br>
<b>Some fields were not filled in. Please Try Again</b>.</p>”;
}
?>
Name:
<input name=”Name” type=”text” size=”40″ value=<? echo $Name; ?>>
Email Address:
<input name=”Email” type=”text” size=”40″ value=<? echo $Email; ?>>
Add Image:
<input name=”fileatt” type=”file” id=”fileatt” size=”40″>
Commentsan:
<textarea name=”Comments” rows=”5″ cols=”50″ value=<? echo $Comments; ?>></textarea>
<input type=”submit” name=”Submit” value=”Submit”>
<input type=”reset” name=”Reset” value=”Clear Form”>
</form>
Here is my email script:
[code=php]
<?php
$error = 0;
if (($Name == “”) ||($Email == “” )|| ($Comments == “”))
{
$error = 1;
}
if ($error == 1)
{
$l = “Location: [url]http://www.websiteaddress.com/contact1.php?error=1[/url]”;
$l .=”&Name=$Name&Email=$Email&Comments=$Comments”;
header($l);
exit;
}
//Define some variables
foreach($_FILES as $value) {
foreach($value as $k => $v) {
echo $k.’ => ‘.$v.'<br>’;
}
}
if($_FILES[‘fileatt’][‘name’] == ”) {
echo ‘You did not select a photo to upload’;
}
elseif($_FILES[‘fileatt’][‘size’] == 0) {
echo ‘There appears to be a problem with the photo your are uploading’;
}
elseif($_FILES[‘fileatt’][‘size’] > $MAX_FILE_SIZE) {
echo ‘The photo you selected is too large’;
}
elseif(!getimagesize($_FILES[‘fileatt’][‘tmp_name’
])) {
echo ‘The photo you selected is not a valid image file’;
}
else {
$uploaddir = ‘uploads/’; // remember the trailing slash!
$uploadfile = $uploaddir . $_FILES[“fileatt”][‘name’];
if(move_uploaded_file($_FILES[‘fileatt’][‘tmp_name
‘], $uploadfile)) {
echo ‘Upload file success!’;
}
else {
echo ‘There was a problem uploading your file.<br>’;
print_r($_FILES);
}
}
$youremail=”[email protected]”;
$emailsubject=”Contact!”;
$from_who=”<[email protected]>”;
$pagetitle=”Thank You!”;
if (getenv(HTTP_CLIENT_IP)){
$user_ip=getenv(HTTP_CLIENT_IP);
}
else {
$user_ip=getenv(REMOTE_ADDR);
}
$Name = $_POST[‘Name’];
$Email = $_POST[‘Email’];
$Comments = $_POST[‘Comments’];
$datafile = $_POST[‘datafile’];
$mailbody=”Senders Name:n=================n$Namenn”;
$mailbody.=”Senders Email:n=================n$Emailnn”;
$mailbody.=”Senders Comments:n=================n$Comments”;
mail(“$youremail”, “$emailsubject”, “$mailbody”, “From: $from_who”); // Send the email.
$comments = nl2br($comments);
$k = “Location: [url]http://www.websiteaddress.com/contact_thanks1.php?[/url]”;
header($k);
?>
Please Help Me i’m going crazy
LOL Thanks