Index: branches/feature-module-update/data/class/GC_SendMail.php
===================================================================
--- branches/feature-module-update/data/class/GC_SendMail.php	(revision 16282)
+++ branches/feature-module-update/data/class/GC_SendMail.php	(revision 16302)
@@ -5,44 +5,102 @@
  * http://www.lockon.co.jp/
  */
+ 
+require_once(dirname(__FILE__) . '/../module/Mail/Mail.php');
+require_once(dirname(__FILE__) . '/../module/Mail/mime.php');
 
 //--- テキスト/HTML　メール送信
 class GC_SendMail {
 
-	var	$html;			//	HTML メールヘッダー
 	var $to;			//	送信先
 	var $subject;		//	題名
 	var $body;			//	本文
-	var $header;		//	ヘッダー
-	var $return_path;	//　return path
-	var $mailer;
-
+	var $cc;			// CC
+	var $bcc;			// BCC
+	var $replay_to;		// replay_to
+	var $return_path;	// return_path
+	var $arrEncode;
+	var $objMailMime;
+	var $arrTEXTEncode;
+	var $arrHTMLEncode;
+	var $objMail;
+			
+	// コンストラクタ
+	function GC_SendMail() {
+		$this->to = "";
+		$this->subject = "";
+		$this->body = "";
+		$this->cc = "";
+		$this->bcc = "";
+		$this->replay_to = "";
+		$this->return_path = "";
+		$this->arrEncode = array();
+		$this->host = SMTP_HOST;
+		$this->port = SMTP_PORT;
+		$this->objMailMime = new Mail_mime();
+		mb_language( "Japanese" );
+		$this->arrTEXTEncode['text_charset'] = "ISO-2022-JP";
+		$this->arrHTMLEncode['head_charset'] = "ISO-2022-JP";
+        $this->arrHTMLEncode['html_encoding'] = "ISO-2022-JP";
+        $this->arrHTMLEncode['html_charset'] = "ISO-2022-JP";
+        $arrHost = array(   
+                'host' => $this->host,
+                'port' => $this->port
+        );
+        //-- PEAR::Mailを使ってメール送信オブジェクト作成
+        $this->objMail =& Mail::factory("smtp", $arrHost);
+	}
+	
+	// 宛先の設定
 	function setTo($to, $to_name = "") {
-		if($to_name != "") {
-			$name = ereg_replace("<","＜", $to_name);
-			$name = ereg_replace(">","＞", $name);
-			
-			if(OS_TYPE != 'WIN') {
-				// windowsでは文字化けするので使用しない。
-				$name = mb_convert_encoding($name,"JIS",CHAR_CODE);	
+		$this->to = $this->getNameAddress($to_name, $to);
+	}
+	
+	// SMTPサーバの設定
+	function setHost($host) {
+		$this->host = $host;
+		$arrHost = array(   
+                'host' => $this->host,
+                'port' => $this->port
+        );
+        //-- PEAR::Mailを使ってメール送信オブジェクト作成
+        $this->objMail =& Mail::factory("smtp", $arrHost);
+		
+	}
+	
+	// SMTPポートの設定
+	function setPort($port) {
+		$this->port = $port;
+		$arrHost = array(   
+                'host' => $this->host,
+                'port' => $this->port
+        );
+        //-- PEAR::Mailを使ってメール送信オブジェクト作成
+        $this->objMail =& Mail::factory("smtp", $arrHost);		
+	}
+	
+	// 名前<メールアドレス>の形式を生成
+	function getNameAddress($name, $mail_address) {
+			if($name != "") {
+				// 制御文字を変換する。				
+				$_name = $name;				
+				$_name = ereg_replace("<","＜", $_name);
+				$_name = ereg_replace(">","＞", $_name);
+				if(OS_TYPE != 'WIN') {
+					// windowsでは文字化けするので使用しない。
+					$_name = mb_convert_encoding($_name,"JIS",CHAR_CODE);	
+				}
+				$_name = mb_encode_mimeheader($_name);
+				$name_address = "\"". $_name . "\"<" . $mail_address . ">";
+			} else {
+				$name_address = $mail_address;
 			}
-			
-			$name = mb_encode_mimeheader($name);
-			$this->to = $name . "<" . $to . ">";
-		} else {
-			$this->to = $to;
-		}
+			return $name_address;
 	}
 	
 	function setItem( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
-		$this->header		 = "Mime-Version: 1.0\n";
-		$this->header		.= "Content-Type: text/plain; charset=ISO-2022-JP\n";
-		$this->header		.= "Content-Transfer-Encoding: 7bit\n";
 		$this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
 	}
-		
+	
 	function setItemHtml( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
-		$this->header		 = "Mime-Version: 1.0\n";
-		$this->header		.= "Content-Type: text/html; charset=ISO-2022-JP\n";
-		$this->header		.= "Content-Transfer-Encoding: 7bit\n";
 		$this->setBase($to, $subject, $body, $fromaddress, $from_name, $reply_to, $return_path, $errors_to, $bcc, $cc);
 	}
@@ -61,51 +119,84 @@
 	*/		
 	function setBase( $to, $subject, $body, $fromaddress, $from_name, $reply_to="", $return_path="", $errors_to="", $bcc="", $cc ="" ) {
+		// 宛先設定
 		$this->to			 = $to;
+		// 件名設定
 		$this->subject		 = mb_encode_mimeheader($subject);
-
-		// iso-2022-jpだと特殊文字が？で送信されるのでJISを使用する。
+		// 本文設定(iso-2022-jpだと特殊文字が？で送信されるのでJISを使用する)
 		$this->body			 = mb_convert_encoding( $body, "JIS", CHAR_CODE);
-				
-		// ヘッダーに日本語を使用する場合はMb_encode_mimeheaderでエンコードする。
-		$from_name = ereg_replace("<","＜", $from_name);
-		$from_name = ereg_replace(">","＞", $from_name);
-		
-		if(OS_TYPE != 'WIN') {
-			// windowsでは文字化けするので使用しない。
-			$from_name = mb_convert_encoding($from_name,"JIS",CHAR_CODE);		
-		}
-		
-		$this->header.= "From: ". mb_encode_mimeheader( $from_name )."<".$fromaddress.">\n";
-
+		// 送信元設定
+		$this->from = $this->getNameAddress($from_name, $fromaddress);
+		// 返信先設定
 		if($reply_to != "") {
-			$this->header.= "Reply-To: ". $reply_to . "\n";			
+			$this->reply_to = $reply_to;			
+		}		
+		// CC設定
+		if($cc != "") {
+			$this->cc = $cc;	
+		}
+		// BCC設定
+		if($bcc != "") {
+			$this->bcc = $bcc;			
+		}
+		// Errors-Toは、ほとんどのSMTPで無視され、Return-Pathが優先されるためReturn_Pathに設定する。
+		if($errors_to != "") {
+			$this->return_path = $errors_to;
+		} else if($return_path != "") {
+			$this->return_path = $return_path;
 		} else {
-			$this->header.= "Reply-To: ". $fromaddress . "\n";			
-		}
-		
-		if($cc != "") {
-			$this->header.= "Cc: " . $cc. "\n";			
-		}
-		
-		if($bcc != "") {
-			$this->header.= "Bcc: " . $bcc . "\n";			
-		}
-
-		if($errors_to != "") {
-			$this->header.= "Errors-To: ". $errors_to ."\n";
-		}
-	}
-	
-	//	メール送信を実行する
+			$this->return_path = $fromaddress;
+		}
+	}
+	
+	// ヘッダーを返す
+	function getHeader() {
+		//-- 送信するメールの内容と送信先
+		$arrHeader['To'] = $this->to;
+		$arrHeader['Subject'] = $this->subject;
+		$arrHeader['From'] = $this->from;
+		$arrHeader['Return-Path'] = $this->return_path;
+		
+		if($this->reply_to != "") {
+			$arrHeader['Reply'] = $this->reply_to;
+		}
+		
+		if($this->cc != "") {
+			$arrHeader['Cc'] = $this->cc;
+		}
+		
+		if($this->bcc != "") {		
+			$arrHeader['Bcc'] = $this->bcc;
+		}
+		return $arrHeader;
+	}
+	
+	//	TXTメール送信を実行する
 	function sendMail() {
-		return $this->sendHtmlMail();
-	}
-
+		$this->objMailMime->setTXTBody($this->body);
+		$body = $this->objMailMime->get($this->arrTEXTEncode);
+		$header = $this->getHeader();
+        // メール送信
+        $result = $this->objMail->send($this->to, $header, $body);           
+		if (PEAR::isError($result)) { 
+			GC_Utils_Ex::gfPrintLog($result->getMessage());
+			GC_Utils_Ex::gfDebugLog($header);
+			return false;		
+		}
+		return true;		
+	}
+	
+	// HTMLメール送信を実行する
 	function sendHtmlMail() {
-		//　メール送信
-		if( mail( $this->to, $this->subject, $this->body, $this->header) ) {
-			return true;
-		}
-		return false;
+		$this->objMailMime->setHTMLBody($this->body);
+		$body = $this->objMailMime->get($this->arrHTMLEncode);
+		$header = $this->getHeader();
+        // メール送信
+        $result = $this->objMail->send($this->to, $header, $body);           
+		if (PEAR::isError($result)) { 
+			GC_Utils_Ex::gfPrintLog($result->getMessage());
+			GC_Utils_Ex::gfDebugLog($header);	
+			return false;
+		}
+		return true;
 	}
 }
