Source for file SC_Helper_Mail.php
Documentation is available at SC_Helper_Mail.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @author LOCKON CO.,LTD.
* @version $Id: SC_Helper_Mail.php 21302 2011-10-28 09:58:18Z shutta $
$masterData = new SC_DB_MasterData_Ex();
$this->arrMAILTPLPATH = $masterData->getMasterData("mtb_mail_tpl_path");
$this->arrPref = $masterData->getMasterData('mtb_pref');
/* DBに登録されたテンプレートメールの送信 */
function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "", $bcc = '') {
$objQuery = new SC_Query_Ex();
$where = "template_id = ?";
$arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
$objPage->tpl_header = $arrRet[0]['header'];
$objPage->tpl_footer = $arrRet[0]['footer'];
$tmp_subject = $arrRet[0]['subject'];
$arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
$objMailView = new SC_SiteView_Ex();
$objMailView->assignobj($objPage);
$objSendMail = new SC_SendMail_Ex();
if ($from_address == "") $from_address = $arrInfo['email03'];
if ($from_name == "") $from_name = $arrInfo['shop_name'];
if ($reply_to == "") $reply_to = $arrInfo['email03'];
$error = $arrInfo['email04'];
$objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error, $bcc);
$objSendMail->setTo($to, $to_name);
$objSendMail->sendMail(); // メール送信
function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
$arrTplVar = new stdClass();
$arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
$arrTplVar->arrInfo = $arrInfo;
$objQuery = new SC_Query_Ex();
if($subject == "" && $header == "" && $footer == "") {
$where = "template_id = ?";
$arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
$arrTplVar->tpl_header = $arrRet[0]['header'];
$arrTplVar->tpl_footer = $arrRet[0]['footer'];
$tmp_subject = $arrRet[0]['subject'];
$arrTplVar->tpl_header = $header;
$arrTplVar->tpl_footer = $footer;
$arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
$objQuery->setOrder('order_detail_id');
$arrTplVar->arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
$objProduct = new SC_Product_Ex();
$objQuery->setOrder('shipping_id');
$arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($order_id));
$objQuery->setOrder('shipping_id');
$arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
array($order_id, $arrRet[$key]['shipping_id']));
foreach ($arrItems as $itemKey => $arrDetail) {
foreach ($arrDetail as $detailKey => $detailVal) {
$arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
$arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] = & $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
$arrTplVar->arrShipping = $arrRet;
$arrTplVar->Message_tmp = $arrOrder['message'];
$customer_id = $arrOrder['customer_id'];
$objQuery->setOrder('customer_id');
$arrRet = $objQuery->select('point', "dtb_customer", "customer_id = ?", array($customer_id));
$arrCustomer = isset ($arrRet[0]) ? $arrRet[0] : "";
$arrTplVar->arrCustomer = $arrCustomer;
$arrTplVar->arrOrder = $arrOrder;
if($arrOrder['memo02'] != "") {
foreach($arrOther as $other_key => $other_val){
if(SC_Utils_Ex::sfTrim($other_val['value']) == ""){
$arrOther[$other_key]['value'] = "";
$arrTplVar->arrOther = $arrOther;
$arrTplVar->arrPref = $this->arrPref;
$objCustomer = new SC_Customer_Ex();
$arrTplVar->tpl_user_point = $objCustomer->getValue('point');
if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
$objMailView = new SC_MobileView_Ex();
$objMailView = new SC_SiteView_Ex();
$objMailView->assignobj($arrTplVar);
$objSendMail = new SC_SendMail_Ex();
$bcc = $arrInfo['email01'];
$from = $arrInfo['email03'];
$error = $arrInfo['email04'];
$objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
$objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] . " 様");
if ($objSendMail->sendMail()) {
$objMailView = new SC_SiteView_Ex();
$arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
$objPage->tpl_shopname= $arrInfo['shop_name'];
$objPage->tpl_infoemail = $arrInfo['email02'];
$objMailView->assignobj($objPage);
$body = $objMailView->fetch($tplpath);
$objSendMail = new SC_SendMail_Ex();
$bcc = $arrInfo['email01'];
$from = $arrInfo['email03'];
$error = $arrInfo['email04'];
$objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
$objSendMail->sendMail();
$arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
$objSendMail = new SC_SendMail_Ex();
$bcc = $arrInfo['email01'];
$from = $arrInfo['email03'];
$error = $arrInfo['email04'];
$objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
$objSendMail->sendMail();
if (empty($objMailView)) {
$objMailView = new SC_SiteView_Ex();
$objTplAssign = new stdClass;
$arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
$objTplAssign->tpl_shopname= $arrInfo['shop_name'];
$objTplAssign->tpl_infoemail= $subject; // 従来互換
$objTplAssign->tpl_mailtitle= $subject;
$objMailView->assignobj($objTplAssign);
$subject = $objMailView->fetch('mail_templates/mail_title.tpl');
$sqlval['subject'] = $subject;
$sqlval['order_id'] = $order_id;
$sqlval['template_id'] = $template_id;
$sqlval['send_date'] = 'CURRENT_TIMESTAMP';
if (!isset ($_SESSION['member_id'])) $_SESSION['member_id'] = "";
if($_SESSION['member_id'] != "") {
$sqlval['creator_id'] = $_SESSION['member_id'];
$sqlval['creator_id'] = '0';
$sqlval['mail_body'] = $body;
$objQuery = new SC_Query_Ex();
$sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id");
$objQuery->insert("dtb_mail_history", $sqlval);
/* 会員登録があるかどうかのチェック(仮会員を含まない) */
$col = "email, mailmaga_flg, customer_id";
$where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
$objQuery = new SC_Query_Ex();
$arrRet = $objQuery->select($col, $from, $where, array($email));
if(!empty($arrRet[0]['customer_id'])) {
* @param string $secret_key 会員固有キー
* @param integer $customer_id 顧客ID
* @param boolean $is_mobile false(default):PCアドレスにメールを送る true:携帯アドレスにメールを送る
* @return boolean true:成功 false:失敗
if(SC_Utils_Ex::sfIsInt($customer_id)) {
$arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id);
$arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId('', "secret_key = ?", array($secret_key));
if(SC_Utils_Ex::isBlank($arrCustomerData)) {
$CONF = SC_Helper_DB_Ex::sfGetBasisData();
$objMailText = new SC_SiteView_Ex();
$objMailText->assign('CONF', $CONF);
$objMailText->assign("name01", $arrCustomerData['name01']);
$objMailText->assign("name02", $arrCustomerData['name02']);
$objMailText->assign('uniqid', $arrCustomerData['secret_key']);
$objMailText->assignobj($arrCustomerData);
$objMailText->assignobj($this);
$objHelperMail = new SC_Helper_Mail_Ex();
if(CUSTOMER_CONFIRM_MAIL == true and $arrCustomerData['status'] == 1) {
$subject = $objHelperMail->sfMakeSubject('会員登録のご確認', $objMailText);
$toCustomerMail = $objMailText->fetch("mail_templates/customer_mail.tpl");
$subject = $objHelperMail->sfMakeSubject('会員登録のご完了', $objMailText);
$toCustomerMail = $objMailText->fetch("mail_templates/customer_regist_mail.tpl");
, $CONF["email03"] // 配送元アドレス
, $CONF["shop_name"] // 配送元 名前
, $CONF["email03"] // reply_to
, $CONF["email04"] // return_path
, $CONF["email04"] // Errors_to
, $CONF["email01"] // Bcc
$to_addr = $arrCustomerData["email_mobile"];
$to_addr = $arrCustomerData['email'];
$objMail->setTo($to_addr, $arrCustomerData["name01"] . $arrCustomerData["name02"] . " 様");
* @param integer 特定IDのテンプレートを取り出したい時はtemplate_idを指定。未指定時は全件取得
* @return array メールテンプレート情報を格納した配列
$objQuery = & SC_Query_Ex::getSingletonInstance();
if (SC_Utils_Ex::sfIsInt($template_id) === true) {
$where .= ' AND template_id = ?';
$arrValues[] = $template_id;
$objQuery->setOrder("create_date DESC");
$arrResults = $objQuery->select('*', 'dtb_mailmaga_template', $where, $arrValues);
* @param integer 特定の送信履歴を取り出したい時はsend_idを指定。未指定時は全件取得
* @return array 送信履歴情報を格納した配列
$objQuery = & SC_Query_Ex::getSingletonInstance();
if (SC_Utils_Ex::sfIsInt($send_id) === true) {
$where .= ' AND send_id = ?';
$objQuery->setOrder("create_date DESC");
$arrResults = $objQuery->select('*', 'dtb_send_history', $where, $arrValues);
* @param integer $send_id dtb_send_history の情報
$objQuery = & SC_Query_Ex::getSingletonInstance();
$objDb = new SC_Helper_DB_Ex();
$objSite = $objDb->sfGetBasisData();
$objMail = new SC_SendMail_Ex();
$where = 'del_flg = 0 AND send_id = ?';
$arrMail = $objQuery->getRow('*', 'dtb_send_history', $where, array($send_id));
if (SC_Utils_Ex::isBlank($arrMail)) return;
$arrDestinationList = $objQuery->select(
'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)',
$complete_count = $arrMail['complete_count'];
if(SC_Utils_Ex::isBlank($arrMail)) $complete_count = 0;
foreach ($arrDestinationList as $arrDestination) {
$customerName = trim($arrDestination['name']);
$subjectBody = preg_replace("/{name}/", $customerName, $arrMail['subject']);
$mailBody = preg_replace("/{name}/", $customerName, $arrMail['body']);
$arrDestination['email'],
$objSite["email03"], // 送信元メールアドレス
$objSite["shop_name"], // 送信元名
$objSite["email03"], // reply_to
$objSite["email04"], // return_path
$objSite["email04"] // errors_to
if ($arrMail["mail_method"] == 2) {
$sendResut = $objMail->sendMail();
$sendResut = $objMail->sendHtmlMail();
// 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入
$objQuery->update('dtb_send_customer',
array('send_flag'=> $sendFlag),
'send_id = ? AND customer_id = ?',
array($send_id,$arrDestination["customer_id"]));
$objQuery->update('dtb_send_history',
array('end_date'=> 'CURRENT_TIMESTAMP', 'complete_count'=> $complete_count),
$compSubject = date("Y年m月d日H時i分") . " 下記メールの配信が完了しました。";
$objMail->setTo($objSite["email03"]);
$objMail->setSubject($compSubject);
if ($arrMail["mail_method"] == 2 ) {
$sendResut = $objMail->sendMail();
$sendResut = $objMail->sendHtmlMail();
Documentation generated on Fri, 24 Feb 2012 14:02:44 +0900 by Seasoft
|