i have a php mail form already that i made that works great, but I cant seem to figure out how to get it to upload the file to the listed directory on my site when someone attaches a file. i would rather have it actually send it in the mail instead of uploading to my server, but cant figure that one out either. the only reason i have been stuck on uploading to the file was because i have a script i found that allows me to do that, but cant figure out what i am doing wornge when trying to add just that feature to my current script. if you know the MIME header stuff well enough and can get it to actually just send me the mail without having to uploa to the server, let me know. here is my current code, maybe you can help fix it so it works.
PHP Code:
<?
$mailto = 'jstgermain@methodcomptech.com' ;
$subject = "MCT Web Mail" ;
$formurl = "http://www.methodcomptech.com/methodemail.html" ;
$errorurl = "http://www.methodcomptech.com/error.html" ;
$thankyouurl = "http://www.methodcomptech.com/success.html" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$website = $_POST['website'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from: " . $name .
"\n$http_referrer\n\n" .
"________________________( COMMENTS )________________________\n\n" .
"\nName: " . $name .
"\nE-Mail: " . $email .
"\nPhone Number: " . $phone .
"\nWeb-Site: " . $website .
"\n\nMessage: \n" . $comments .
"\n\n____________________________________________________________\n" ;
// --THIS IS THE CODE I ADDED TO TRY AND GET IT TO UPLOAD THE FILE, HAS TO BE SOMETHING WRONGE HERE-- //
$up_full = "http://www.methodcomptech.com/upload";
$up_dir = "./upload/";
$UploadNum = "1";
$online_isp = "0";
$status = '';
$new_name = '';
$uploaded = '';
$get_files = '';
$all_names = '';
for($i=0;$i<count($_FILES["fileup"]["tmp_name"]);$i++)
{
$name=$_FILES["fileup"]["name"][$i];
$temp=$_FILES["fileup"]["tmp_name"][$i];
$size=$_FILES["fileup"]["size"][$i];
$type=$_FILES["fileup"]["type"][$i];
if($size > 0)
{
global $up_dir, $all_names;
$length = 1;
$key_chars = '';
$rand_max = strlen($key_chars);
for ($i = 0; $i < $length; $i++)
{
$rand_pos = rand(0, $rand_max);
$rand_key[] = $key_chars{$rand_pos};
}
$rand_pass = implode('', $rand_key);
$boom = strlen($Msg) * strlen($From);
$timer = time()* rand(0, $boom);
$timer = $timer . '-' . $rand_pass;
$new_name = $name;
$new_name = str_replace(" ","_",$new_name);
@move_uploaded_file($temp, $up_dir . $new_name);
$all_names.= "$new_name\n";
}
}
// -------------------------------------END OF THE ADDED CODE---------------------------------------- //
mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: feedback.php" );
header( "Location: $thankyouurl" );
exit ;
?>
please let me know if anyone out there knows what I did wronge. I can't figure it out.
Bookmarks