Hi I am having a problem can't seem to get my script working it was working fine with just one file before without the for and $x statements I have added can anyone see why it isn't working please ?

html

<form name="iapply3" method="post" action="ionline4.php">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<tr><td colspan="2" class="head">PHOTO </td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>

<tr><td colspan="2" class="head">PHOTO</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>

php

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


        $to = 'info@apa.com';
        $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
        // headers
        $headers .= "From: APA <noreply@apa.com>\n";  
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
        // message
        $message = "--{$boundary}\n";
        $message .= "Content-Type: text/html; charset=iso-8859-1\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "<html>

<head>
<title>HTML message</title>

</head>
<body>
hello
if(is_uploaded_file($fileatt)){
for($x=0;$x<count($fileatt);$x++)
{

    $fp = fopen($fileatt[$x], 'rb');
    $data = fread($fp, filesize($fileatt[$x]));
    fclose($fp);
    $data = chunk_split(base64_encode($data));
    $message .= "--{$boundary}\n";
    $message .= "Content-Type: $fileatt_type[$x];\n name=\"$fileatt_name[$x]\"\n";
    //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name[$x]\"\n";
    $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n";
    $message .= "--{$boundary}--\n";
}
}

        mail($to, $subject, $message, $headers);

I can't see how this would work even with one file; there are no PHP tags! Furthermore, can you describe what doesn't work when you input two files? Actual PHP errors, or it doesn't add one/both to the message?

of course the php page already has <?php ?> tags and before you ask the html page also has <php> <html> and <body> tags lol

And it doesn't work sends the email fine but doesn't attch the files?

You are adding two boundaries for each file. Move your second boundary addition outside of the loop.

mm tried that didn't work thanks for the suggestion though

almost have it working now but its only emailing one file?

foreach ($_FILES["fileatt"]["error"] as $key => $error) { 
        if ($error == UPLOAD_ERR_OK) { 
$fileatt = $_FILES['fileatt']['tmp_name'][$key];
$fileatt_type = $_FILES['fileatt']['type'][$key];
$fileatt_name = $_FILES['fileatt']['name'][$key]; 


        // attachment
        $fp = fopen($fileatt, 'rb');
        $data = fread($fp, filesize($fileatt));
        fclose($fp);

        $data = chunk_split(base64_encode($data));
        $message .= "--{$boundary}\n";
        $message .= "Content-Type: $fileatt_type;\n name=\"$fileatt_name\"\n";
        //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name\"\n";
        $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n";
        //$message .= "--{$boundary}--\n";
      
       
    } 
}


        mail($to, $subject, $message, $headers);

i am close to saying EUREKA but unfortunately not. now it sends both the attachments they have the correct file names types in the email but they are all unreadable? jpg gif pdf .doc .txt the .txt file did open though and had this in it

Content-Disposition: attachment; filename="/tmp/phpS6Wyy3"

and nothing else

here is the code i am using

<? 
session_start();
error_reporting(apa);
error_reporting(7);
include("../secure/global/connection.php");


        $to = 'info@website.com';
        $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
        // headers
        $headers .= "From: Website name <noreply@website.com>\n";  
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
        // message
        $message = "--{$boundary}\n";
        $message .= "Content-Type: text/html; charset=iso-8859-1\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "<html>
<head>
<title>HTML message</title>

</head>
<body>
hello testing

</body>
</html>";



foreach ($_FILES["fileatt"]["error"] as $key => $error) { 
        if ($error == UPLOAD_ERR_OK) { 
$fileatt = $_FILES['fileatt']['tmp_name'][$key];
$fileatt_type = $_FILES['fileatt']['type'][$key];
$fileatt_name = $_FILES['fileatt']['name'][$key]; 


        
        // attachment
        $fp = fopen($fileatt, 'rb');
        $data = fread($fp, filesize($fileatt));
        fclose($fp);

        $data = chunk_split(base64_encode($data)); 
        $message .= $data . "\n";
        $message .= "--{$boundary}\n";
        $message .= "Content-Type: application/$fileatt_type; name=\"$fileatt_name\"\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "Content-Disposition: attachment; filename=\"$fileatt\"\n\n";  



       
    } 
}


        mail($to, $subject, $message, $headers);
    

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.