Im stuck now it is day four, I have a bunch of clients that upload documents to the web server, the code works if I maually type the names of the documents into the array, but that is not what I want, Mysql has table called "transact" with a field "documents" that the document name is stored under.

I pull the email address already from the tabel, It sends the email perfectly but the attachements are suposed to be two files, it is now one file but the name of that file is one long name like 1234567.pdf2341234556.pdf

Adobe does not open it, so I guess there is a probem with my arry assigning or something, In line 35 and 36 I have tried using "; " and ", " and even spaces but nothing works, it is something stupid in my array im doing I know, can someone point me in teh right direction

My maual Array looks like this and it works perfectly I get the files:

$files = array("1003020122510160249.pdf","1003020122510160248.pdf");

But I want it form MYSQL here is my code:

<?php
include_once "db_conf.php";

// GET PREVIOUS DATA FROM PAGE
$clientid = $_GET['id'];
$emailname = $_POST['mails'];
$mailbody = $_POST['comments'];

        //SEARCH FOR EMAIL ADDRESS IN MAIL TABLE
        $sql="SELECT * FROM mails where name='$emailname'"; 
        $result=mysql_query($sql); 

        //CLEAR THE OPTIONS
        $options=""; 

        while ($row=mysql_fetch_array($result)) { 
            $id=$row["id"]; 
            $name=$row["name"]; 
            $tomail=$row["email"]; 
        } 


// RETRIEVE DOCUMENT NAMES THAT NEED TO BE SENT AS ATTACHMENTS
        $query = "SELECT document FROM transact WHERE clientid=$clientid";
        $result = mysql_query($query) or die (mysql_error());
        while ($record = mysql_fetch_array($result)) {

//ARRAY DATA
        $arr[] = $record['document'];


    }

//DOCUMENT NAME ARRAY
    $docz = implode("; ",$arr);
    $rray = ''.$docz.'';

//ASSIGN ARRAY NAMES TO FILES TO BE SENT
    //$files = $rray;
    $files = array($rray);
    $filecount=count($files);



// email fields: to, from, subject, and so on   
$to = $tomail;
$from = "info@email.com"; 
$subject ="Query RE: $clientid "; 
$message = $mailbody;
$headers = "From: $from";

// boundary 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

// headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

// multipart 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"; 
$message .= "--{$mime_boundary}\n";

// preparing attachments
for($x=0;$x<count($files);$x++){
    $file = fopen($files[$x],"rb");
    $data = fread($file,filesize($files[$x]));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $message .= "--{$mime_boundary}\n";
}

// SEND MY EMAILS WITH THE ATTACHEMNTS
$ok = @mail($to, $subject, $message, $headers); 
if ($ok) { 
    echo "<p>mail sent to $to!</p>"; 
} else { 
    echo "<p>mail could not be sent!</p>"; 
} 
?>

I am stumped here How do I split the file names in that array.

Mike

You do a lot of copying... why not use $arr, and remove all the weird copying that happens after that. $arr is already an array.

Tried that .. it send me a blank .DAT file, line 40 would then look like this

$files = array($arr);

Basically I need to find a way to split the name, it comes thorugh in my email as

"1003020122510160249.pdf1003020122510160248.pdf" yet the file should be two files "1003020122510160249.pdf" And "1003020122510160248.pdf" not one single one with one long name - I guess my code joins the file names so the ; or , or ' or something should be the problem or it is the IMPLODE that is wrong ... sigh (banging my head against the desk)

You should remove lines 34-41, and from line 64 onwards, use $arr instead of $files.

lol ... sorry now im getting Array.dat file in my email. Replaced code from line

// RETRIEVE DOCUMENT NAMES THAT NEED TO BE SENT AS ATTACHMENTS
        $query = "SELECT document FROM transact WHERE clientid=$clientid";
        $result = mysql_query($query) or die (mysql_error());
        while ($record = mysql_fetch_array($result)) {

//ARRAY DATA
        $arr[] = $record['document'];


    }


    $filecount=count($arr);



// email fields: to, from, subject, and so on   
$to = $tomail;
$from = "info@email.com"; 
$subject ="Query RE: $clientid "; 
$message = $mailbody;
$headers = "From: $from"; 

The count is important as some clients have one attachemnt others have 10 or more

The count is important

You don't even use $filecount.

If you don't show what you changed I can't help you.

Ok, guess RTFS (READ THE F@#$% SCREEN ) is the main thing ... lol
I did not read the screen, replaced $file AND $files with $arr
You need another sigar mate :)

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.