Hi can anyone help me check the code for this why cant send multiple attachment with this code got anything wrong. Help me please

if($to == '0'){
$ok=@mail($to, $subject, $body, $headers);
}else {
$ok=@mail($to, $subject, $body, $headers);


$fields = array();
$fields{"from"} = "Name";
$fields{"email"} = "Email";
$fields{"phone"} = "Phone Ext";
$fields{"ip"}="IP Address";
$fields{"problem"} = "Request";

$body = "Here is the following detail:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$fileatt      = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$fileatt      = $_FILES['fileatt2']['tmp_name'2];
$fileatt_type = $_FILES['fileatt2']['type2'];
$fileatt_name = $_FILES['fileatt2']['name2'];

$fileatt      = $_FILES['fileatt3']['tmp_name3'];
$fileatt_type = $_FILES['fileatt3']['type3'];
$fileatt_name = $_FILES['fileatt3']['name3'];

$headers = "From: $from";

if (is_uploaded_file($fileatt,$fileatt2.$fileatt3)) {

  $file = fopen($fileatt,$fileatt2.$fileatt3,'rb');
  $data = fread($file,filesize($fileatt));

  $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}\"";

  $body = "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" .
             $body . "\n\n";

  $data = chunk_split(base64_encode($data));

  $body .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .

if($from == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent, You have not entered a Name, please go back fill up and try again!!')</script>";}

else {

if($phone == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Phone Ext, please go back fill up and try again!!')</script>";}

else {

if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";}



$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
  echo "<p>Thank you for using the system. Your request have be sent. We will get back to you shortly. Please be patient, thank you !</p>";
} else {
  echo "<p>SYSTEM BUSY! Mail Could not be Sent ! Please Try it Later!</p>";
9 Years
Discussion Span
Last Post by chrishea

Just a comment. I once spent a lot of time trying to get mailing to work correctly, especially when adding attachments and so forth. I found the Libmail class and downloaded it and I haven't looked back. The interface is simple and it works every time. I know that there are lots of people who enjoy re-inventing the wheel and far be it from me to get in the way of that. If you just want to send mail with the minimum time and effort, Libmail works.
I think I made one change to it to and that was to allow the To field to accept addresses separated by commas. If anyone wants my version, I can post it on my site.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.