Pear-Mail_Mimeを使って添付メールを送信

 <?php
 
 //error_reporting(0);
 
 include 'Mail.php';
 include 'Mail/mime.php' ;
 
 $text = '日本語の文章';
 $text = mb_convert_encoding($text, "ISO-2022-JP", "UTF-8");
 $subject = 'テストメール';
 $subject = mb_convert_encoding($subject, "ISO-2022-JP", "UTF-8");
 $subject = mb_encode_mimeheader($subject, "ISO-2022-JP");
 $html = '<html><body>HTML version of email</body></html>';
 $file = 'test.txt';
 $crlf = "\n";
 $hdrs = array(
               'From'    => 'hanako@gmail.com',
               'Subject' => $subject,
               );
 
 $mime = new Mail_mime(array('eol' => $crlf, 'text_charset' => 'ISO-2022-JP'));
 
 $mime->setTXTBody($text);
 #$mime->setHTMLBody($html);
 $mime->addAttachment($file, 'text/plain');
 
 $body = $mime->get();
 $hdrs = $mime->headers($hdrs);
 
 $mail =& Mail::factory('mail');
 $mail->send('taro@gmail.com', $hdrs, $body);
 
 ?>

参考


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2012-05-25 (金) 20:20:34