Changeset 16302


Ignore:
Timestamp:
2007/10/06 21:30:10 (16 years ago)
Author:
naka
Message:

GC_SendMailをMail_mime()に対応させる。

Location:
branches/feature-module-update/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/GC_SendMail.php

    r16282 r16302  
    55 * http://www.lockon.co.jp/ 
    66 */ 
     7  
     8require_once(dirname(__FILE__) . '/../module/Mail/Mail.php'); 
     9require_once(dirname(__FILE__) . '/../module/Mail/mime.php'); 
    710 
    811//--- テキスト/HTML メール送信 
    912class GC_SendMail { 
    1013 
    11     var $html;          //  HTML メールヘッダー 
    1214    var $to;            //  送信先 
    1315    var $subject;       //  題名 
    1416    var $body;          //  本文 
    15     var $header;        //  ヘッダー 
    16     var $return_path;   // return path 
    17     var $mailer; 
    18  
     17    var $cc;            // CC 
     18    var $bcc;           // BCC 
     19    var $replay_to;     // replay_to 
     20    var $return_path;   // return_path 
     21    var $arrEncode; 
     22    var $objMailMime; 
     23    var $arrTEXTEncode; 
     24    var $arrHTMLEncode; 
     25    var $objMail; 
     26             
     27    // コンストラクタ 
     28    function GC_SendMail() { 
     29        $this->to = ""; 
     30        $this->subject = ""; 
     31        $this->body = ""; 
     32        $this->cc = ""; 
     33        $this->bcc = ""; 
     34        $this->replay_to = ""; 
     35        $this->return_path = ""; 
     36        $this->arrEncode = array(); 
     37        $this->host = SMTP_HOST; 
     38        $this->port = SMTP_PORT; 
     39        $this->objMailMime = new Mail_mime(); 
     40        mb_language( "Japanese" ); 
     41        $this->arrTEXTEncode['text_charset'] = "ISO-2022-JP"; 
     42        $this->arrHTMLEncode['head_charset'] = "ISO-2022-JP"; 
     43        $this->arrHTMLEncode['html_encoding'] = "ISO-2022-JP"; 
     44        $this->arrHTMLEncode['html_charset'] = "ISO-2022-JP"; 
     45        $arrHost = array(    
     46                'host' => $this->host, 
     47                'port' => $this->port 
     48        ); 
     49        //-- PEAR::Mailを使ってメール送信オブジェクト作成 
     50        $this->objMail =& Mail::factory("smtp", $arrHost); 
     51    } 
     52     
     53    // 宛先の設定 
    1954    function setTo($to, $to_name = "") { 
    20         if($to_name != "") { 
    21             $name = ereg_replace("<","<", $to_name); 
    22             $name = ereg_replace(">",">", $name); 
    23              
    24             if(OS_TYPE != 'WIN') { 
    25                 // windowsでは文字化けするので使用しない。 
    26                 $name = mb_convert_encoding($name,"JIS",CHAR_CODE);  
     55        $this->to = $this->getNameAddress($to_name, $to); 
     56    } 
     57     
     58    // SMTPサーバの設定 
     59    function setHost($host) { 
     60        $this->host = $host; 
     61        $arrHost = array(    
     62                'host' => $this->host, 
     63                'port' => $this->port 
     64        ); 
     65        //-- PEAR::Mailを使ってメール送信オブジェクト作成 
     66        $this->objMail =& Mail::factory("smtp", $arrHost); 
     67         
     68    } 
     69     
     70    // SMTPポートの設定 
     71    function setPort($port) { 
     72        $this->port = $port; 
     73        $arrHost = array(    
     74                'host' => $this->host, 
     75                'port' => $this->port 
     76        ); 
     77        //-- PEAR::Mailを使ってメール送信オブジェクト作成 
     78        $this->objMail =& Mail::factory("smtp", $arrHost);       
     79    } 
     80     
     81    // 名前<メールアドレス>の形式を生成 
     82    function getNameAddress($name, $mail_address) { 
     83            if($name != "") { 
     84                // 制御文字を変換する。                
     85                $_name = $name;              
     86                $_name = ereg_replace("<","<", $_name); 
     87                $_name = ereg_replace(">",">", $_name); 
     88                if(OS_TYPE != 'WIN') { 
     89                    // windowsでは文字化けするので使用しない。 
     90                    $_name = mb_convert_encoding($_name,"JIS",CHAR_CODE);    
     91                } 
     92                $_name = mb_encode_mimeheader($_name); 
     93                $name_address = "\"". $_name . "\"<" . $mail_address . ">"; 
     94            } else { 
     95                $name_address = $mail_address; 
    2796            } 
    28              
    29             $name = mb_encode_mimeheader($name); 
    30             $this->to = $name . "<" . $to . ">"; 
    31         } else { 
    32             $this->to = $to; 
    33         } 
     97            return $name_address; 
    3498    } 
    3599     
    36100    function setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) { 
    37         $this->header        = "Mime-Version: 1.0\n"; 
    38         $this->header       .= "Content-Type: text/plain; charset=ISO-2022-JP\n"; 
    39         $this->header       .= "Content-Transfer-Encoding: 7bit\n"; 
    40101        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc); 
    41102    } 
    42          
     103     
    43104    function setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) { 
    44         $this->header        = "Mime-Version: 1.0\n"; 
    45         $this->header       .= "Content-Type: text/html; charset=ISO-2022-JP\n"; 
    46         $this->header       .= "Content-Transfer-Encoding: 7bit\n"; 
    47105        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc); 
    48106    } 
     
    61119    */       
    62120    function setBase( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) { 
     121        // 宛先設定 
    63122        $this->to            = $to; 
     123        // 件名設定 
    64124        $this->subject       = mb_encode_mimeheader($subject); 
    65  
    66         // iso-2022-jpだと特殊文字が?で送信されるのでJISを使用する。 
     125        // 本文設定(iso-2022-jpだと特殊文字が?で送信されるのでJISを使用する) 
    67126        $this->body          = mb_convert_encoding( $body, "JIS", CHAR_CODE); 
    68                  
    69         // ヘッダーに日本語を使用する場合はMb_encode_mimeheaderでエンコードする。 
    70         $from_name = ereg_replace("<","<", $from_name); 
    71         $from_name = ereg_replace(">",">", $from_name); 
    72          
    73         if(OS_TYPE != 'WIN') { 
    74             // windowsでは文字化けするので使用しない。 
    75             $from_name = mb_convert_encoding($from_name,"JIS",CHAR_CODE);        
    76         } 
    77          
    78         $this->header.= "From: ". mb_encode_mimeheader( $from_name )."<".$fromaddress.">\n"; 
    79  
     127        // 送信元設定 
     128        $this->from = $this->getNameAddress($from_name, $fromaddress); 
     129        // 返信先設定 
    80130        if($reply_to != "") { 
    81             $this->header.= "Reply-To: ". $reply_to . "\n";          
     131            $this->reply_to = $reply_to;             
     132        }        
     133        // CC設定 
     134        if($cc != "") { 
     135            $this->cc = $cc;     
     136        } 
     137        // BCC設定 
     138        if($bcc != "") { 
     139            $this->bcc = $bcc;           
     140        } 
     141        // Errors-Toは、ほとんどのSMTPで無視され、Return-Pathが優先されるためReturn_Pathに設定する。 
     142        if($errors_to != "") { 
     143            $this->return_path = $errors_to; 
     144        } else if($return_path != "") { 
     145            $this->return_path = $return_path; 
    82146        } else { 
    83             $this->header.= "Reply-To: ". $fromaddress . "\n";           
    84         } 
    85          
    86         if($cc != "") { 
    87             $this->header.= "Cc: " . $cc. "\n";          
    88         } 
    89          
    90         if($bcc != "") { 
    91             $this->header.= "Bcc: " . $bcc . "\n";           
    92         } 
    93  
    94         if($errors_to != "") { 
    95             $this->header.= "Errors-To: ". $errors_to ."\n"; 
    96         } 
    97     } 
    98      
    99     //  メール送信を実行する 
     147            $this->return_path = $fromaddress; 
     148        } 
     149    } 
     150     
     151    // ヘッダーを返す 
     152    function getHeader() { 
     153        //-- 送信するメールの内容と送信先 
     154        $arrHeader['To'] = $this->to; 
     155        $arrHeader['Subject'] = $this->subject; 
     156        $arrHeader['From'] = $this->from; 
     157        $arrHeader['Return-Path'] = $this->return_path; 
     158         
     159        if($this->reply_to != "") { 
     160            $arrHeader['Reply'] = $this->reply_to; 
     161        } 
     162         
     163        if($this->cc != "") { 
     164            $arrHeader['Cc'] = $this->cc; 
     165        } 
     166         
     167        if($this->bcc != "") {       
     168            $arrHeader['Bcc'] = $this->bcc; 
     169        } 
     170        return $arrHeader; 
     171    } 
     172     
     173    //  TXTメール送信を実行する 
    100174    function sendMail() { 
    101         return $this->sendHtmlMail(); 
    102     } 
    103  
     175        $this->objMailMime->setTXTBody($this->body); 
     176        $body = $this->objMailMime->get($this->arrTEXTEncode); 
     177        $header = $this->getHeader(); 
     178        // メール送信 
     179        $result = $this->objMail->send($this->to, $header, $body);            
     180        if (PEAR::isError($result)) {  
     181            GC_Utils_Ex::gfPrintLog($result->getMessage()); 
     182            GC_Utils_Ex::gfDebugLog($header); 
     183            return false;        
     184        } 
     185        return true;         
     186    } 
     187     
     188    // HTMLメール送信を実行する 
    104189    function sendHtmlMail() { 
    105         // メール送信 
    106         if( mail( $this->to, $this->subject, $this->body, $this->header) ) { 
    107             return true; 
    108         } 
    109         return false; 
     190        $this->objMailMime->setHTMLBody($this->body); 
     191        $body = $this->objMailMime->get($this->arrHTMLEncode); 
     192        $header = $this->getHeader(); 
     193        // メール送信 
     194        $result = $this->objMail->send($this->to, $header, $body);            
     195        if (PEAR::isError($result)) {  
     196            GC_Utils_Ex::gfPrintLog($result->getMessage()); 
     197            GC_Utils_Ex::gfDebugLog($header);    
     198            return false; 
     199        } 
     200        return true; 
    110201    } 
    111202} 
  • branches/feature-module-update/data/install.php

    r15532 r16302  
    11<?php 
     2    define ('ECCUBE_INSTALL', 'ON'); 
     3    define ('HTML_PATH', 'C:\mydir\pdt\workspace\feature-module-update/html/'); 
     4    define ('SITE_URL', 'http://update.ec-cube.net/'); 
     5    define ('SSL_URL', 'http://update.ec-cube.net/'); 
     6    define ('URL_DIR', '/'); 
     7    define ('DOMAIN_NAME', ''); 
     8    define ('DB_TYPE', 'pgsql'); 
     9    define ('DB_USER', 'nanasess'); 
     10    define ('DB_PASSWORD', 'nanasess'); 
     11    define ('DB_SERVER', '192.168.0.70'); 
     12    define ('DB_NAME', 'naka_db'); 
     13    define ('DB_PORT', ''); 
     14    define ('DATA_PATH', 'C:\mydir\pdt\workspace\feature-module-update/data/'); 
     15    define ('MOBILE_HTML_PATH', HTML_PATH . 'mobile/'); 
     16    define ('MOBILE_SITE_URL', SITE_URL . 'mobile/'); 
     17    define ('MOBILE_SSL_URL', SSL_URL . 'mobile/'); 
     18    define ('MOBILE_URL_DIR', URL_DIR . 'mobile/'); 
    219?> 
  • branches/feature-module-update/data/module/Mail/RFC822.php

    r16300 r16302  
    185185 
    186186        if ($this->address === false || isset($this->error)) { 
    187             require_once 'PEAR.php'; 
     187            require_once dirname(__FILE__) . '/../PEAR.php'; 
    188188            return PEAR::raiseError($this->error); 
    189189        } 
     
    195195 
    196196            if ($valid === false || isset($this->error)) { 
    197                 require_once 'PEAR.php'; 
     197                require_once dirname(__FILE__) . '/../PEAR.php'; 
    198198                return PEAR::raiseError($this->error); 
    199199            } 
Note: See TracChangeset for help on using the changeset viewer.