<?php $email= $_POST['email']; $file01 = $_POST['file01'];; $file02 = $_POST['file02'];; $attach_file = $file01; $attach_file02 = $file02; $to[] = 'hoge@hoge.com'; //$to[] = 'testtest2@yahoo.co.jp'; $from_email= $email; $from_name = '送信者名'; $subject = 'メールのタイトル'; $body = " このメールは、自動で送信されるメールです。 資料を送信致します。 添付ファイルをご参考して下さい。 以上です。 "; // send the email foreach( $to as $to_email ) { sendmail_jpn($to_email, $subject, $body, $from_email,$from_name, $attach_file); sleep(1); } echo "送信完了"; //関数----------------------------------- function sendmail_jpn($to, $subject, $message, $from_email,$from_name, $filepath) { $mime_type = "application/octet-stream"; // 添付ファイルのエンコード $filename = basename($filepath); // マルチパートなので、パートの区切り文字列を指定 $boundary = '----=_Boundary_' . uniqid(rand(1000,9999) . '_') . '_'; // 件名のエンコード $subject = mb_convert_encoding($subject, 'ISO-2022-JP', 'auto'); $subject = mb_encode_mimeheader_ex($subject); // 本文のエンコード $message = mb_convert_encoding($message, 'ISO-2022-JP', 'auto'); // toをエンコード // $to = mb_convert_encoding($mail['to']['name'], "auto", "auto"); $to = "=?ISO-2022-JP?B?" . base64_encode($to) . '?= <' . $to . '>'; // fromをエンコード $from_name = mb_convert_encoding($from_name, 'ISO-2022-JP', 'auto'); $from = "=?ISO-2022-JP?B?" . base64_encode($from_name) . '?= <' . $from_email . '>'; // 添付ファイルのエンコード $filename = mb_convert_encoding($filename, 'ISO-2022-JP', 'auto'); $filename = "=?ISO-2022-JP?B?" . base64_encode($filename) . "?="; // ヘッダーの指定 $head = ""; $head .= "From: {$from}\n"; $head .= "MIME-Version: 1.0\n"; $head .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n"; $head .= "Content-Transfer-Encoding: 7bit"; $body = ""; // 本文 $body .= "--{$boundary}\n"; $body .= "Content-Type: text/plain; charset=ISO-2022-JP;" . "Content-Transfer-Encoding: 7bit\n"; $body .= "\n"; $body .= "{$message}\n"; $body .= "\n"; // 添付ファイルの処理 $body .= "--{$boundary}\n"; $body .= "Content-Type: {$mime_type}; name=\"{$filename}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment; filename=\"{$filename}\"\n"; $body .= "\n"; $fp = fopen( $filepath, "r" ) or die("Error on mailing. (attachment file cannot open)"); $contents = fread( $fp, filesize($filepath) ); fclose( $fp ); $f_encoded = chunk_split(base64_encode($contents)); //添付ファイルをbase64エンコードする $body .= "{$f_encoded}\n"; $body .= "\n"; if (mail($to, $subject, $body, $head)) { echo 'sendmail_jpn : OK.'; } else { echo 'sendmail_jpn : FAILURE.'; } } // mb_encode_mimeheaderのバグ対策用 function mb_encode_mimeheader_ex($text, $split_count = 34) { $position = 0; $encorded = ''; while ($position < mb_strlen($text, 'ISO-2022-JP')) { if ($encorded != '') { $encorded .= "\r\n "; } $output_temp = mb_strimwidth($text, $position, $split_count, '', 'ISO-2022-JP'); $position = $position + mb_strlen($output_temp, 'ISO-2022-JP'); $encorded .= "=?ISO-2022-JP?B?" . base64_encode($output_temp) . "?="; } return $encorded; } ?>
現在ファイル1個は問題なく添付発送できますが
添付ファイルが2個になると
($attach_file02、$attach_file02)どうすればいいでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/04 03:21