複数の文書を添付した電子メールを添付ファイルとして送信する機能があります。ただ問題は、どれだけの文書を送っても、電子メールには1つしか表示されず、破損しているように見えることです。ファイルのパス名は正しいですが、私はこれをテストしましたが、電子メールからドキュメントを開こうとすると、Microsoftの単語が破損したファイルについて文句を言います。誰か私が間違っていることを教えてください?PHPで複数の文書を添付ファイルとして送信
function mail_attachment_multiple($to, $subject, $message, $attachment, $from){//sends email as an attachment. attachment parameter is the path to file
$fileatt_type = "application/msword"; // File Type
$email_from = $from; // Who the email is from
$email_subject = $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it
$email_to = $to; // Who the email is to
$headers = "From: ".$email_from;
$msg_txt="\n\n You have recieved a new attachment message from $from";
$email_message = "";
//loop through array: $key = filename; $value = filenamePATH
foreach($attachment as $key => $value){
$fileatt_name = $key; //name of file
$fileatt_path = $value; // file path (http://www.example.com/filePath)
$file = fopen($fileatt_path,'rb');
$temp = get_headers($fileatt_path, 1);
$file_size = $temp['Content-Length'];
$data = fread($file, $file_size); //filesize($fileatt_path)
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_txt .= $msg_txt;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";
$data[$key] = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_path}\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ."--{$mime_boundary}--\n";
}
return @mail($email_to, $email_subject, $email_message, $headers);?>
ありがとうございました!
いいえ、これは自分で修正してください。 SwiftmailerやPHPmailerでうまく動作している場合、誰にもこれをパッチするべきではありません。スパゲッティコードを使用することはあなたの決定です。 – mario