source: branches/beta/data/class/GC_SendMail.php @ 15366

Revision 15366, 3.4 KB checked in by naka, 17 years ago (diff)

メール送信の修正(Windows対応)

RevLine 
[15366]1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8//--- ¥Æ¥­¥¹¥È/HTML¡¡¥á¡¼¥ëÁ÷¿®
9class GC_SendMail {
10
11    var $html;          //  HTML ¥á¡¼¥ë¥Ø¥Ã¥À¡¼
12    var $to;            //  Á÷¿®Àè
13    var $subject;       //  Âê̾
14    var $body;          //  ËÜʸ
15    var $header;        //  ¥Ø¥Ã¥À¡¼
16    var $return_path;   //¡¡return path
17    var $mailer;
18
19    function setTo($to, $to_name = "") {
20        if($to_name != "") {
21            $name = ereg_replace("<","¡ã", $to_name);
22            $name = ereg_replace(">","¡ä", $name);
23           
24            if(WINDOWS != true) {
25                // windows¤Ç¤Ïʸ»ú²½¤±¤¹¤ë¤Î¤Ç»ÈÍѤ·¤Ê¤¤¡£
26                $name = mb_convert_encoding($name,"JIS",CHAR_CODE);
27            }
28           
29            $name = mb_encode_mimeheader($name);
30            $this->to = $name . "<" . $to . ">";
31        } else {
32            $this->to = $to;
33        }
34    }
35   
36    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";
40        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
41    }
42       
43    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";
47        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
48    }
49
50    /*  ¥Ø¥Ã¥ÀÅù¤ò³ÊǼ
51         $to            -> Á÷¿®Àè¥á¡¼¥ë¥¢¥É¥ì¥¹
52         $subject       -> ¥á¡¼¥ë¤Î¥¿¥¤¥È¥ë
53         $body          -> ¥á¡¼¥ëËÜʸ
54         $fromaddress   -> Á÷¿®¸µ¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹
55         $header        -> ¥Ø¥Ã¥À¡¼
56         $from_name     -> Á÷¿®¸µ¤Î̾Á°¡ÊÁ´³ÑOK¡Ë
57         $reply_to      -> reply_toÀßÄê
58         $return_path   -> return-path¥¢¥É¥ì¥¹ÀßÄê¡Ê¥¨¥é¡¼¥á¡¼¥ëÊÖÁ÷ÍÑ¡Ë
59         $cc            -> ¥«¡¼¥Ü¥ó¥³¥Ô¡¼
60         $bcc           -> ¥Ö¥é¥¤¥ó¥É¥«¡¼¥Ü¥ó¥³¥Ô¡¼
61    */     
62    function setBase( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
63        $this->to            = $to;
64        $this->subject       = mb_encode_mimeheader($subject);
65
66        // iso-2022-jp¤À¤ÈÆüìʸ»ú¤¬¡©¤ÇÁ÷¿®¤µ¤ì¤ë¤Î¤ÇJIS¤ò»ÈÍѤ¹¤ë¡£
67        $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(WINDOWS != true) {
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
80        if($reply_to != "") {
81            $this->header.= "Reply-To: ". $reply_to . "\n";         
82        } 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    //  ¥á¡¼¥ëÁ÷¿®¤ò¼Â¹Ô¤¹¤ë
100    function sendMail() {
101        return $this->sendHtmlMail();
102    }
103
104    function sendHtmlMail() {
105        //¡¡¥á¡¼¥ëÁ÷¿®
106        if( mail( $this->to, $this->subject, $this->body, $this->header) ) {
107            return true;
108        }
109        return false;
110    }
111}
112
[8]113?>
Note: See TracBrowser for help on using the repository browser.