How to send content as HTML if I use attachment and in header i have some else?
firstly I get Files, than a type a message, than send it like mime_boundaty. I need a to change content type in one place. did it`s possible?
$files = array();
function reArrayFiles(&$file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$new_arr = array();
array_push($new_arr,$file_post[$key][$i]);
$file_ary[$i][$key] = $new_arr;
}
}
return $file_ary;
}
foreach($_FILES as $file) {
$file = reArrayFiles($file);
foreach($file as $name=>$file1) {
for($i=0; $i<count($file1);$i++){
}
if($file1['error'][0]!='4')
array_push($files,$file1);
}
}
// email fields: to, from, subject, and so on
$to = "contact@amil.com";
$from = $_POST['mail'];
$subject = "Quote request: ".$_POST['ttle'].' ';
$message = "Full name:".$_POST['name'].' ';
$message.= "Email:".$_POST['mail'].' ';
$message.= "Description:".$_POST['descr'].' ';
$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++){
// echo $files[$x];
// echo '<br>-----------------------<br>';
$file = fopen($files[$x]['tmp_name'][0],"rb");
$data = fread($file,filesize($files[$x]['tmp_name'][0]));
fclose($file);
$data = chunk_split(base64_encode($data));
$name = $files[$x]['name'][0];
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = mail($to, $subject, $message, $headers);
if ($ok) {
header('Location: index.php');
} else {
header('Location: index.php');
}
}
?>`