function sendMail( $to=null, $sender_email=null, $from = null,$subject=null, $text=null, $file=null, $file2=null, $file3=null, $file_path=null, $file_path2=null, $file_path3=null){
$mail['to']['name'] = $from;
$mail['to']['mail'] = $to;
$mail['from']['name'] = $from;
$mail['from']['mail'] = $sender_email;
$subject = $subject;
$message = $text;
$filename = $file;
$attach_file = $file_path; // 添付ファイル へのパス
$attach_file2 = $file_path2; // 添付ファイル へのパス
$attach_file3 = $file_path3; // 添付ファイル へのパス
$mime_type = "application/octet-stream";
// 文字エンコードの設定
mb_internal_encoding('UTF-8');
// マルチパートなので、パートの区切り文字列を指定
$boundary = '----=_Boundary_' . uniqid(rand(1000,9999) . '_') . '_';
// 件名のエンコード
$subject = mb_convert_encoding($subject, 'ISO-2022-JP', 'UTF-8');
$subject = $this->mb_encode_mimeheader_ex($subject);
// 本文のエンコード
$message = mb_convert_encoding($message, 'ISO-2022-JP', 'UTF-8');
// toをエンコード
$to = mb_convert_encoding($mail['to']['name'], "JIS", "UTF-8");
$to = "=?ISO-2022-JP?B?" . base64_encode($to) . '?= <' . $mail['to']['mail'] . '>';
// fromをエンコード
$from = mb_convert_encoding($mail['from']['name'], "JIS", "UTF-8");
$from = "=?ISO-2022-JP?B?" . base64_encode($from) . '?= <' . $mail['from']['mail'] . '>';
// 添付ファイルのエンコード
$filename = mb_convert_encoding($filename, 'ISO-2022-JP', 'UTF-8');
$filename = "=?ISO-2022-JP?B?" . base64_encode($filename) . "?=";
$attach_file = file_get_contents($attach_file); // ファイルを開く
$attach_file = chunk_split(base64_encode($attach_file), 76, "\n"); // Base64に変換し76Byte分割
$attach_file2 = file_get_contents($attach_file2); // ファイルを開く
$attach_file2 = chunk_split(base64_encode($attach_file2), 76, "\n"); // Base64に変換し76Byte分割
$attach_file3 = file_get_contents($attach_file3); // ファイルを開く
$attach_file3 = chunk_split(base64_encode($attach_file3), 76, "\n"); // Base64に変換し76Byte分割
// ヘッダーの指定
$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\n" .
"Content-Transfer-Encoding: 7bit\n";
$body .= "\n";
$body .= "{$message}\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";
$body .= "{$attach_file}\n";
// ファイル添付2
if( !empty($file2) ) {
$body .= "--{$boundary}\n";
$body .= "Content-Type: {$mime_type}; name=\"{$file2}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment; filename=\"{$file2}\"\n";
$body .= "\n";
$body .= "{$attach_file2}\n";
}
// ファイル添付3
if( !empty($file3) ) {
$body .= "--{$boundary}\n";
$body .= "Content-Type: {$mime_type}; name=\"{$file3}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment; filename=\"{$file3}\"\n";
$body .= "\n";
$body .= "{$attach_file3}\n";
}
// マルチパートの終了
$body .= "--$boundary--\n";
if (mail($to, $subject, $body, $head)) {
//echo '送信完了';
} else {
//echo '送信できませんでした。';
}
return false;
}
// 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;
}