source: branches/dev/data/class/GC_SendMail.php @ 15150

Revision 15150, 3.2 KB checked in by naka, 14 years ago (diff)
Line 
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    /*  ¥Ø¥Ã¥ÀÅù¤ò³ÊǼ
20         $to            -> Á÷¿®Àè¥á¡¼¥ë¥¢¥É¥ì¥¹
21         $subject       -> ¥á¡¼¥ë¤Î¥¿¥¤¥È¥ë
22         $body          -> ¥á¡¼¥ëËÜʸ
23         $fromaddress   -> Á÷¿®¸µ¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹
24         $header        -> ¥Ø¥Ã¥À¡¼
25         $from_name     -> Á÷¿®¸µ¤Î̾Á°¡ÊÁ´³ÑOK¡Ë
26         $reply_to      -> reply_toÀßÄê
27         $return_path   -> return-path¥¢¥É¥ì¥¹ÀßÄê¡Ê¥¨¥é¡¼¥á¡¼¥ëÊÖÁ÷ÍÑ¡Ë
28         $cc            -> ¥«¡¼¥Ü¥ó¥³¥Ô¡¼
29         $bcc           -> ¥Ö¥é¥¤¥ó¥É¥«¡¼¥Ü¥ó¥³¥Ô¡¼
30    */ 
31    function setTo($to, $to_name = "") {
32        if($to_name != "") {
33            $name = ereg_replace("<","¡ã", $to_name);
34            $name = ereg_replace(">","¡ä", $name);
35            $name = mb_encode_mimeheader(mb_convert_encoding($name, "JIS", CHAR_CODE));
36            $this->to = $name . "<" . $to . ">";
37        } else {
38            $this->to = $to;
39        }
40    }
41   
42    function setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
43        $this->header        = "Mime-Version: 1.0\n";
44        $this->header       .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
45        $this->header       .= "Content-Transfer-Encoding: 7bit\n";
46        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
47    }
48       
49    function setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
50        $this->header        = "Mime-Version: 1.0\n";
51        $this->header       .= "Content-Type: text/html; charset=ISO-2022-JP\n";
52        $this->header       .= "Content-Transfer-Encoding: 7bit\n";
53        $this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
54    }
55   
56    function setBase( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
57       
58        $this->to            = $to;
59        $this->subject       = mb_encode_mimeheader($subject);
60
61        // iso-2022-jp¤À¤ÈÆüìʸ»ú¤¬¡©¤ÇÁ÷¿®¤µ¤ì¤ë¤Î¤ÇJIS¤ò»ÈÍѤ¹¤ë¡£
62        $this->body          = mb_convert_encoding( $body, "JIS", CHAR_CODE);
63               
64        // ¥Ø¥Ã¥À¡¼¤ËÆüËܸì¤ò»ÈÍѤ¹¤ë¾ì¹ç¤ÏMb_encode_mimeheader¤Ç¥¨¥ó¥³¡¼¥É¤¹¤ë¡£
65        $from_name = ereg_replace("<","¡ã", $from_name);
66        $from_name = ereg_replace(">","¡ä", $from_name);
67        $from_name = mb_convert_encoding($from_name,"JIS",CHAR_CODE);
68       
69        $this->header.= "From: ". mb_encode_mimeheader( $from_name )."<".$fromaddress.">\n";
70
71        if($reply_to != "") {
72            $this->header.= "Reply-To: ". $reply_to . "\n";         
73        } else {
74            $this->header.= "Reply-To: ". $fromaddress . "\n";         
75        }
76       
77        if($cc != "") {
78            $this->header.= "Cc: " . $cc. "\n";         
79        }
80       
81        if($bcc != "") {
82            $this->header.= "Bcc: " . $bcc . "\n";         
83        }
84
85        if($errors_to != "") {
86            $this->header.= "Errors-To: ". $errors_to ."\n";
87        }
88    }
89   
90    //  ¥á¡¼¥ëÁ÷¿®¤ò¼Â¹Ô¤¹¤ë
91    function sendMail() {
92        return $this->sendHtmlMail();
93    }
94
95    function sendHtmlMail() {
96        //¡¡¥á¡¼¥ëÁ÷¿®
97        if( mail( $this->to, $this->subject, $this->body, $this->header) ) {
98            return true;
99        }
100        return false;
101    }
102}
103
104?>
Note: See TracBrowser for help on using the repository browser.