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