Author Topic: Help making mailing both form content and file  (Read 211 times)

0 Members and 1 Guest are viewing this topic.

Offline weiner769Topic starter

  • Irregular
  • Posts: 1
    • View Profile
Help making mailing both form content and file
« on: February 08, 2010, 06:36:34 PM »
I have a form on my website that needs to send both text information and files.  I have tried for the past week to get the php right and it does not seem to want to cooperate lol
my php script is as follows:
<?php
 $to
'_@gmail.com';
 
$subject'Application';
 
$from'Website';
 
$fname $_POST['fname'] ;
 
$lname $_POST['lname'] ;
 
$phone $_POST['phone'] ;
 
$email $_POST['email'] ;
 
$state $_POST['state'] ;
 
$city $_POST['city'] ;
 
$about $_POST['about'] ;
 
$experience $_POST['experience'] ;
  
 
$fileatt      $_FILES['fileatt']['tmp_name'];     
 
$fileatt_type $_FILES['fileatt']['type'];     
 
$fileatt_name $_FILES['fileatt']['name'];
 
$headers "From: $fname";
 if (
is_uploaded_file($fileatt)) {        
 
$file fopen($fileatt,'rb');     
 
$data fread($file,filesize($fileatt));     
 
fclose($file);

 
$semi_rand md5(time());     
 
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";     
 
$headers .= "\nMIME-Version: 1.0\n" .     
             
"Content-Type: multipart/mixed;\n" .     
             
" boundary=\"{$mime_boundary}\"";
 
$message "This is a multi-part message in MIME format.\n\n" .     
            
"--{$mime_boundary}\n" .     
            
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .     
            
"Content-Transfer-Encoding: 7bit\n\n" .     
            
$message "\n\n";
 
$data chunk_split(base64_encode($data));
 
$message .= "--{$mime_boundary}\n" .     
             
"Content-Type: {$fileatt_type};\n" .     
             
" name=\"{$fileatt_name}\"\n" .     
             
"Content-Disposition: attachment;\n" .     
             
" filename=\"{$fileatt_name}\"\n" .     
             
"Content-Transfer-Encoding: base64\n\n" .     
             
$data "\n\n" .     
             
"--{$mime_boundary}--\n";     
}

 
$bodystripslashes ('fname ' $fname ' lname ' $lname ' phone ' $phone ' email ' $email ' state ' $state ' city ' $city '  about ' $about ' experience ' $experience $from) ;
  
 
$okmail$to$subject$message$headers$body);
  if (
$ok) {     
 echo 
"<p>Form temporarily unavaliable</p>";     
} else {     
 echo 
"<p>Mail could not be sent. Sorry!</p>";     
}     

?><title>sendmail.php</title>



I would prefer to send multiple files as attachments, but nowhere have I seen that that is possible.  I really appreciate your time, thanks!

Offline WolfRage

  • Devotee
  • Posts: 651
  • Gender: Male
    • View Profile
    • Feral Bytes
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
Please be forewarned; rather than giving you exactly what you want I prefer to teach you how to get what you want. Knowledge is power, so take the time to learn PHP and you will be able to wield it's power.
If I just gave you the code to solve your problem then you will be back again tomorrow asking for more of the same code. So please take the time to learn. Thanks.