PDA

View Full Version : Question on PHP Mail Form



jstgermain
01-11-2006, 01:16 PM
I currently have a couple php mail forms I created, but I am completely lost when it comes to trying to get an attachment sent to. Does anyone have a good PHP form where people can upload and image, dozument, zip file, ect. to the server and mail it to me. The mail form will be set to ALWAYS be sent to me since it is coming from my site, but I am not sure how to add the attach a document function in. If anyone knows this, please help, and THANKS in advance.

Thanks,
Justin St. Germain

Twey
01-11-2006, 04:45 PM
You need to be fairly familiar with how MIME headers work. See http://codewalkers.com/seecode/98.html for an example.

jstgermain
01-11-2006, 07:08 PM
You need to be fairly familiar with how MIME headers work. See http://codewalkers.com/seecode/98.html for an example.

I understand the MIME headers, but not sure how to use them for the attachment, but i will look at that script in the mean time. I however did find a way to actually make a file attachment upload to my server in a hidden file that is protected by .htaccess, and it seems to work quite nice, but i will look at this too. thanks for your help

jstgermain
01-11-2006, 08:28 PM
i still am confused as how to make that work, so i am going to go with having it upload the files to my server unless you know where i can get a full working script where i just need to mod the info on where it is having the mail sent. thanks again for the help. :)

Twey
01-12-2006, 02:53 PM
Try this (http://www.phpclasses.org/browse/package/1633.html). It's an easy-to-use class. Don't forget to check out the documentation.

jstgermain
01-13-2006, 05:13 PM
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.



<?

$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.