[PHP-users 9707] 添付メール送信に関して

Akinobu YAMAMOTO php-users@php.gr.jp
Tue, 03 Sep 2002 21:38:54 +0900


どうも、山本です。

PHP4.2.2上で添付メール送信ができるWebメールフォームを作成しているのですが、
どうも、Subjectが文字化けしてしまって、解決方法に困っております。
以下がその添付メール送信のfunctionです。

==========================================================================
function sendAttachMail($from,$to,$subject,$body,$attach,$filename){
         $boundary = "-*-*-*-*-*-*-*-*-Boundary_" . uniqid("b");

         // サブジェクトを jis にして、MIME エンコード
         $subject = i18n_mime_header_encode(i18n_convert($subject,"JIS"));

         // 添付するデータを、base64 でエンコードして、RFC に適した書式に
         if ($attach != ""){ $attach = chunk_split(base64_encode($attach)); }

         // メールの送信
         $mp = popen("/usr/sbin/sendmail -f $from $to", "w");

         //##################### メールの組み上げ
         // 全体のヘッダ
         fputs($mp, "MIME-Version: 1.0\n");
         fputs($mp, "Content-Type: Multipart/Mixed; boundary=\"$boundary\"\n");
         fputs($mp, "Content-Transfer-Encoding:Base64\n");
         fputs($mp, "From: $from\n");
         fputs($mp, "To: $to\n");
         fputs($mp, "Subject: $subject\n");

         // メール本文のパート
         fputs($mp, "--$boundary\n");
         fputs($mp, "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n");
         fputs($mp, "\n");
         fputs($mp, "$body\n");

         // 添付ファイルのパート
         if ($attach != "" && $filename != ""){
                 fputs($mp, "--$boundary\n");
                 fputs($mp, "Content-Type: application/octet-stream; name=\"$filename\"\n");
                 fputs($mp, "Content-Transfer-Encoding: base64\n");
                 fputs($mp, "Content-Disposition: attachment; filename=\"$filename\"\n");
                 fputs($mp, "\n");
                 fputs($mp, "$attach\n");
                 fputs($mp, "\n");
         }

         // マルチパートのおわり。
         fputs($mp, "--$boundary" . "--\n");
         pclose($mp);
}
==========================================================================
この中の
         $subject = i18n_mime_header_encode(i18n_convert($subject,"JIS"));
の部分ですが、
         $subject = i18n_convert($subject,"JIS");
にしたり、
         $subject = i18n_mime_header_encode($subject);
にしても文字化けは改善されませんでした。

恐れ入りますが、解決方法がございましたらご指導・ご鞭撻のほど
お願いいたします。
またmb_send_mail関数での添付メールの送信方法がありましたら
それも併せてお願いいたします。


------------------------------------------------
Akinobu YAMAMOTO
ayamamot@freeshop.co.jp

総合無料情報  FreeShop
http://www.freeshop.co.jp/
------------------------------------------------
本発言は特に明記がない限り、私山本の個人的なもので、
所属組織(freeshop.co.jp)には関係有りません。