Прикрепить файл документа в электронной почте php?

Я использую следующий код, чтобы прикрепить файл по электронной почте, письмо получено с символом вложения, но открытие письма не содержит ничего.

    $semi_rand = md5(time());
$from = "test@domainname.com";
$headers = "From: " . $fromEmailName . " ". "\r\n" ;

$headers .= "cc: " . $fromEmailName . " <" . $cc . ">" . "\r\n" ;$boundary = "==Multipart_Boundary_x{$semi_rand}x";

// headers used for send attachment with email
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"           {$boundary}\"";$message = "--{$boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-  Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$boundary}\n";$fileatt = $_FILES["file"]["tmp_name"]; // Path to the tmp file
$fileatt_type = "text/plain"; // File Type
$fileatt_name = "upload.doc"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$fname\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$boundary}\n";

mail($to, $subject, $message, $headers, "-f " . $from)

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …