[15618] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15618] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[15618] | 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * メール関連 のヘルパークラス. |
---|
| 26 | * |
---|
| 27 | * @package Helper |
---|
| 28 | * @author LOCKON CO.,LTD. |
---|
| 29 | * @version $Id$ |
---|
| 30 | */ |
---|
| 31 | class SC_Helper_Mail { |
---|
| 32 | |
---|
| 33 | /** メールテンプレートのパス */ |
---|
| 34 | var $arrMAILTPLPATH; |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * コンストラクタ. |
---|
| 38 | */ |
---|
| 39 | function SC_Helper_Mail() { |
---|
| 40 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 41 | $this->arrMAILTPLPATH = $masterData->getMasterData("mtb_mail_tpl_path"); |
---|
[19773] | 42 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
[15618] | 43 | } |
---|
| 44 | |
---|
| 45 | /* DBに登録されたテンプレートメールの送信 */ |
---|
[17375] | 46 | function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "") { |
---|
[15618] | 47 | |
---|
[20507] | 48 | $objQuery = new SC_Query_Ex(); |
---|
[15618] | 49 | // メールテンプレート情報の取得 |
---|
| 50 | $where = "template_id = ?"; |
---|
| 51 | $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id)); |
---|
| 52 | $objPage->tpl_header = $arrRet[0]['header']; |
---|
| 53 | $objPage->tpl_footer = $arrRet[0]['footer']; |
---|
| 54 | $tmp_subject = $arrRet[0]['subject']; |
---|
| 55 | |
---|
[20459] | 56 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 57 | |
---|
[20306] | 58 | $objMailView = new SC_SiteView_Ex(); |
---|
[15618] | 59 | // メール本文の取得 |
---|
| 60 | $objMailView->assignobj($objPage); |
---|
[15622] | 61 | $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]); |
---|
[15618] | 62 | |
---|
| 63 | // メール送信処理 |
---|
[16503] | 64 | $objSendMail = new SC_SendMail_Ex(); |
---|
[17375] | 65 | if ($from_address == "") $from_address = $arrInfo['email03']; |
---|
| 66 | if ($from_name == "") $from_name = $arrInfo['shop_name']; |
---|
| 67 | if ($reply_to == "") $reply_to = $arrInfo['email03']; |
---|
[15618] | 68 | $error = $arrInfo['email04']; |
---|
[20469] | 69 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[20540] | 70 | |
---|
[17375] | 71 | $objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error); |
---|
[15618] | 72 | $objSendMail->setTo($to, $to_name); |
---|
[16181] | 73 | $objSendMail->sendMail(); // メール送信 |
---|
[15618] | 74 | } |
---|
| 75 | |
---|
| 76 | /* 受注完了メール送信 */ |
---|
| 77 | function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) { |
---|
| 78 | |
---|
[19749] | 79 | $arrTplVar = new stdClass(); |
---|
[20459] | 80 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[19749] | 81 | $arrTplVar->arrInfo = $arrInfo; |
---|
[15618] | 82 | |
---|
[20507] | 83 | $objQuery = new SC_Query_Ex(); |
---|
[15618] | 84 | |
---|
| 85 | if($subject == "" && $header == "" && $footer == "") { |
---|
| 86 | // メールテンプレート情報の取得 |
---|
| 87 | $where = "template_id = ?"; |
---|
[17375] | 88 | $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id)); |
---|
[19749] | 89 | $arrTplVar->tpl_header = $arrRet[0]['header']; |
---|
| 90 | $arrTplVar->tpl_footer = $arrRet[0]['footer']; |
---|
[15618] | 91 | $tmp_subject = $arrRet[0]['subject']; |
---|
| 92 | } else { |
---|
[19749] | 93 | $arrTplVar->tpl_header = $header; |
---|
| 94 | $arrTplVar->tpl_footer = $footer; |
---|
[15618] | 95 | $tmp_subject = $subject; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // 受注情報の取得 |
---|
| 99 | $where = "order_id = ?"; |
---|
| 100 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
---|
| 101 | $arrOrder = $arrRet[0]; |
---|
[20435] | 102 | $objQuery->setOrder('order_detail_id'); |
---|
[19978] | 103 | $arrTplVar->arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id)); |
---|
[15618] | 104 | |
---|
[20487] | 105 | $objProduct = new SC_Product_Ex(); |
---|
[19978] | 106 | $objQuery->setOrder('shipping_id'); |
---|
| 107 | $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($order_id)); |
---|
| 108 | foreach (array_keys($arrRet) as $key) { |
---|
| 109 | $objQuery->setOrder('shipping_id'); |
---|
| 110 | $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?", |
---|
| 111 | array($order_id, $arrRet[$key]['shipping_id'])); |
---|
| 112 | foreach ($arrItems as $itemKey => $arrDetail) { |
---|
| 113 | foreach ($arrDetail as $detailKey => $detailVal) { |
---|
| 114 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | $arrTplVar->arrShipping = $arrRet; |
---|
| 121 | |
---|
[19749] | 122 | $arrTplVar->Message_tmp = $arrOrder['message']; |
---|
[15618] | 123 | |
---|
| 124 | // 顧客情報の取得 |
---|
| 125 | $customer_id = $arrOrder['customer_id']; |
---|
[19978] | 126 | $objQuery->setOrder('customer_id'); |
---|
[20538] | 127 | $arrRet = $objQuery->select('point', "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
[16189] | 128 | $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : ""; |
---|
[15618] | 129 | |
---|
[19749] | 130 | $arrTplVar->arrCustomer = $arrCustomer; |
---|
| 131 | $arrTplVar->arrOrder = $arrOrder; |
---|
[15618] | 132 | |
---|
| 133 | //その他決済情報 |
---|
| 134 | if($arrOrder['memo02'] != "") { |
---|
| 135 | $arrOther = unserialize($arrOrder['memo02']); |
---|
| 136 | |
---|
| 137 | foreach($arrOther as $other_key => $other_val){ |
---|
[20538] | 138 | if(SC_Utils_Ex::sfTrim($other_val['value']) == ""){ |
---|
| 139 | $arrOther[$other_key]['value'] = ""; |
---|
[15618] | 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
[19749] | 143 | $arrTplVar->arrOther = $arrOther; |
---|
[15618] | 144 | } |
---|
| 145 | |
---|
| 146 | // 都道府県変換 |
---|
[19978] | 147 | $arrTplVar->arrPref = $this->arrPref; |
---|
[15618] | 148 | |
---|
[20490] | 149 | $objCustomer = new SC_Customer_Ex(); |
---|
[19749] | 150 | $arrTplVar->tpl_user_point = $objCustomer->getValue('point'); |
---|
[15618] | 151 | |
---|
[19897] | 152 | if(Net_UserAgent_Mobile::isMobile() === true) { |
---|
[20306] | 153 | $objMailView = new SC_MobileView_Ex(); |
---|
[19897] | 154 | } else { |
---|
[20306] | 155 | $objMailView = new SC_SiteView_Ex(); |
---|
[19897] | 156 | } |
---|
[15618] | 157 | // メール本文の取得 |
---|
[19749] | 158 | $objMailView->assignobj($arrTplVar); |
---|
[15622] | 159 | $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]); |
---|
[15618] | 160 | |
---|
| 161 | // メール送信処理 |
---|
[16503] | 162 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 163 | $bcc = $arrInfo['email01']; |
---|
| 164 | $from = $arrInfo['email03']; |
---|
| 165 | $error = $arrInfo['email04']; |
---|
[20469] | 166 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[15618] | 167 | |
---|
| 168 | $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
| 169 | $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様"); |
---|
| 170 | |
---|
| 171 | // 送信フラグ:trueの場合は、送信する。 |
---|
| 172 | if($send) { |
---|
| 173 | if ($objSendMail->sendMail()) { |
---|
[15622] | 174 | $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body); |
---|
[15618] | 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | return $objSendMail; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | // テンプレートを使用したメールの送信 |
---|
[17590] | 182 | function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) { |
---|
[20306] | 183 | $objMailView = new SC_SiteView_Ex(); |
---|
[20459] | 184 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 185 | // メール本文の取得 |
---|
| 186 | $objPage->tpl_shopname=$arrInfo['shop_name']; |
---|
| 187 | $objPage->tpl_infoemail = $arrInfo['email02']; |
---|
| 188 | $objMailView->assignobj($objPage); |
---|
| 189 | $body = $objMailView->fetch($tplpath); |
---|
| 190 | // メール送信処理 |
---|
[16503] | 191 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 192 | $bcc = $arrInfo['email01']; |
---|
| 193 | $from = $arrInfo['email03']; |
---|
| 194 | $error = $arrInfo['email04']; |
---|
[20469] | 195 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[20540] | 196 | |
---|
[17590] | 197 | $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
[15618] | 198 | $objSendMail->sendMail(); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | // 通常のメール送信 |
---|
[17590] | 202 | function sfSendMail($to, $tmp_subject, $body) { |
---|
[20459] | 203 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 204 | // メール送信処理 |
---|
[16503] | 205 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 206 | $bcc = $arrInfo['email01']; |
---|
| 207 | $from = $arrInfo['email03']; |
---|
| 208 | $error = $arrInfo['email04']; |
---|
[17590] | 209 | $tosubject = $this->sfMakeSubject($tmp_subject); |
---|
[20540] | 210 | |
---|
[17590] | 211 | $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
[15618] | 212 | $objSendMail->sendMail(); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | //件名にテンプレートを用いる |
---|
[20469] | 216 | function sfMakeSubject($subject, &$objMailView) { |
---|
| 217 | if (empty($objMailView)) { |
---|
| 218 | $objMailView = new SC_SiteView_Ex(); |
---|
| 219 | } |
---|
[17590] | 220 | $objTplAssign = new stdClass; |
---|
[20540] | 221 | |
---|
[20469] | 222 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[17590] | 223 | $objTplAssign->tpl_shopname=$arrInfo['shop_name']; |
---|
| 224 | $objTplAssign->tpl_infoemail=$subject; // 従来互換 |
---|
| 225 | $objTplAssign->tpl_mailtitle=$subject; |
---|
| 226 | $objMailView->assignobj($objTplAssign); |
---|
| 227 | $subject = $objMailView->fetch('mail_templates/mail_title.tpl'); |
---|
| 228 | return $subject; |
---|
[15618] | 229 | } |
---|
| 230 | |
---|
| 231 | // メール配信履歴への登録 |
---|
| 232 | function sfSaveMailHistory($order_id, $template_id, $subject, $body) { |
---|
| 233 | $sqlval['subject'] = $subject; |
---|
| 234 | $sqlval['order_id'] = $order_id; |
---|
| 235 | $sqlval['template_id'] = $template_id; |
---|
| 236 | $sqlval['send_date'] = "Now()"; |
---|
[16588] | 237 | if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = ""; |
---|
[15618] | 238 | if($_SESSION['member_id'] != "") { |
---|
| 239 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 240 | } else { |
---|
| 241 | $sqlval['creator_id'] = '0'; |
---|
| 242 | } |
---|
| 243 | $sqlval['mail_body'] = $body; |
---|
| 244 | |
---|
[20507] | 245 | $objQuery = new SC_Query_Ex(); |
---|
[18788] | 246 | $sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id"); |
---|
[15618] | 247 | $objQuery->insert("dtb_mail_history", $sqlval); |
---|
| 248 | } |
---|
| 249 | |
---|
[16588] | 250 | /* 会員登録があるかどうかのチェック(仮会員を含まない) */ |
---|
[15618] | 251 | function sfCheckCustomerMailMaga($email) { |
---|
| 252 | $col = "email, mailmaga_flg, customer_id"; |
---|
| 253 | $from = "dtb_customer"; |
---|
[16588] | 254 | $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0"; |
---|
[20507] | 255 | $objQuery = new SC_Query_Ex(); |
---|
[15618] | 256 | $arrRet = $objQuery->select($col, $from, $where, array($email)); |
---|
| 257 | // 会員のメールアドレスが登録されている |
---|
[16182] | 258 | if(!empty($arrRet[0]['customer_id'])) { |
---|
[15618] | 259 | return true; |
---|
| 260 | } |
---|
| 261 | return false; |
---|
| 262 | } |
---|
[20160] | 263 | |
---|
| 264 | /** |
---|
| 265 | * 登録メールを送信する。 |
---|
| 266 | * |
---|
| 267 | * @param string $secret_key 顧客固有キー |
---|
| 268 | * @param integer $customer_id 顧客ID |
---|
[20642] | 269 | * @param boolean $is_mobile false(default):PCアドレスにメールを送る true:携帯アドレスにメールを送る |
---|
[20160] | 270 | * @return boolean true:成功 false:失敗 |
---|
| 271 | */ |
---|
| 272 | function sfSendRegistMail($secret_key, $customer_id = '', $is_mobile = false) { |
---|
| 273 | // 顧客データの取得 |
---|
| 274 | if(SC_Utils_Ex::sfIsInt($customer_id)) { |
---|
| 275 | $arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
| 276 | }else{ |
---|
| 277 | $arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId('', "secret_key = ?", array($secret_key)); |
---|
| 278 | } |
---|
| 279 | if(SC_Utils_Ex::isBlank($arrCustomerData)) { |
---|
| 280 | return false; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | $CONF = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[20540] | 284 | |
---|
[20306] | 285 | $objMailText = new SC_SiteView_Ex(); |
---|
[20538] | 286 | $objMailText->assign('CONF', $CONF); |
---|
[20360] | 287 | $objMailText->assign("name01", $arrCustomerData['name01']); |
---|
| 288 | $objMailText->assign("name02", $arrCustomerData['name02']); |
---|
[20538] | 289 | $objMailText->assign('uniqid', $arrCustomerData['secret_key']); |
---|
[20160] | 290 | $objMailText->assignobj($arrCustomerData); |
---|
| 291 | $objMailText->assignobj($this); |
---|
| 292 | |
---|
| 293 | $objHelperMail = new SC_Helper_Mail_Ex(); |
---|
| 294 | |
---|
| 295 | // 仮会員が有効の場合 |
---|
| 296 | if(CUSTOMER_CONFIRM_MAIL == true and $arrCustomerData['status'] == 1) { |
---|
[20469] | 297 | $subject = $objHelperMail->sfMakeSubject('会員登録のご確認', $objMailText); |
---|
[20160] | 298 | $toCustomerMail = $objMailText->fetch("mail_templates/customer_mail.tpl"); |
---|
| 299 | } else { |
---|
[20469] | 300 | $subject = $objHelperMail->sfMakeSubject('会員登録のご完了', $objMailText); |
---|
[20160] | 301 | $toCustomerMail = $objMailText->fetch("mail_templates/customer_regist_mail.tpl"); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | $objMail = new SC_SendMail(); |
---|
| 305 | $objMail->setItem( |
---|
| 306 | '' // 宛先 |
---|
| 307 | , $subject // サブジェクト |
---|
| 308 | , $toCustomerMail // 本文 |
---|
| 309 | , $CONF["email03"] // 配送元アドレス |
---|
| 310 | , $CONF["shop_name"] // 配送元 名前 |
---|
| 311 | , $CONF["email03"] // reply_to |
---|
| 312 | , $CONF["email04"] // return_path |
---|
| 313 | , $CONF["email04"] // Errors_to |
---|
| 314 | , $CONF["email01"] // Bcc |
---|
| 315 | ); |
---|
| 316 | // 宛先の設定 |
---|
| 317 | if($is_mobile) { |
---|
| 318 | $to_addr = $arrCustomerData["email_mobile"]; |
---|
| 319 | }else{ |
---|
[20538] | 320 | $to_addr = $arrCustomerData['email']; |
---|
[20160] | 321 | } |
---|
| 322 | $objMail->setTo($to_addr, $arrCustomerData["name01"] . $arrCustomerData["name02"] ." 様"); |
---|
| 323 | |
---|
| 324 | $objMail->sendMail(); |
---|
| 325 | return true; |
---|
| 326 | } |
---|
[20540] | 327 | |
---|
[20198] | 328 | /** |
---|
[20357] | 329 | * 保存されているメルマガテンプレートの取得 |
---|
[20203] | 330 | * @param integer 特定IDのテンプレートを取り出したい時はtemplate_idを指定。未指定時は全件取得 |
---|
[20198] | 331 | * @return array メールテンプレート情報を格納した配列 |
---|
| 332 | * @todo 表示順も引数で変更できるように |
---|
| 333 | */ |
---|
[20357] | 334 | function sfGetMailmagaTemplate($template_id = null){ |
---|
[20198] | 335 | // 初期化 |
---|
| 336 | $where = ''; |
---|
[20507] | 337 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20540] | 338 | |
---|
[20198] | 339 | // 条件文 |
---|
| 340 | $where = 'del_flg = ?'; |
---|
| 341 | $arrValues[] = 0; |
---|
| 342 | //template_id指定時 |
---|
[20203] | 343 | if (SC_Utils_Ex::sfIsInt($template_id) === true) { |
---|
[20642] | 344 | $where .= ' AND template_id = ?'; |
---|
[20203] | 345 | $arrValues[] = $template_id; |
---|
[20198] | 346 | } |
---|
[20540] | 347 | |
---|
[20198] | 348 | // 表示順 |
---|
| 349 | $objQuery->setOrder("create_date DESC"); |
---|
[20540] | 350 | |
---|
[20198] | 351 | $arrResults = $objQuery->select('*', 'dtb_mailmaga_template', $where, $arrValues); |
---|
| 352 | return $arrResults; |
---|
| 353 | } |
---|
[20540] | 354 | |
---|
[20205] | 355 | /** |
---|
[20357] | 356 | * 保存されているメルマガ送信履歴の取得 |
---|
[20205] | 357 | * @param integer 特定の送信履歴を取り出したい時はsend_idを指定。未指定時は全件取得 |
---|
| 358 | * @return array 送信履歴情報を格納した配列 |
---|
| 359 | */ |
---|
| 360 | function sfGetSendHistory($send_id = null){ |
---|
| 361 | // 初期化 |
---|
| 362 | $where = ''; |
---|
[20507] | 363 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20540] | 364 | |
---|
[20205] | 365 | // 条件文 |
---|
| 366 | $where = 'del_flg = ?'; |
---|
| 367 | $arrValues[] = 0; |
---|
[20540] | 368 | |
---|
[20205] | 369 | //send_id指定時 |
---|
| 370 | if (SC_Utils_Ex::sfIsInt($send_id) === true) { |
---|
[20642] | 371 | $where .= ' AND send_id = ?'; |
---|
[20205] | 372 | $arrValues[] = $send_id; |
---|
| 373 | } |
---|
[20540] | 374 | |
---|
[20205] | 375 | // 表示順 |
---|
| 376 | $objQuery->setOrder("create_date DESC"); |
---|
[20540] | 377 | |
---|
[20205] | 378 | $arrResults = $objQuery->select('*', 'dtb_send_history', $where, $arrValues); |
---|
| 379 | return $arrResults; |
---|
| 380 | } |
---|
[20357] | 381 | |
---|
| 382 | /** |
---|
| 383 | * 指定したIDのメルマガ配送を行う |
---|
[20642] | 384 | * |
---|
[20357] | 385 | * @param integer $send_id dtb_send_history の情報 |
---|
[20361] | 386 | * @return void |
---|
[20357] | 387 | */ |
---|
| 388 | function sfSendMailmagazine($send_id) { |
---|
[20507] | 389 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20357] | 390 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 391 | $objSite = $objDb->sfGetBasisData(); |
---|
| 392 | $objMail = new SC_SendMail_Ex(); |
---|
[20540] | 393 | |
---|
[20357] | 394 | $where = 'del_flg = 0 AND send_id = ?'; |
---|
| 395 | $arrMail = $objQuery->getRow('*', 'dtb_send_history', $where, array($send_id)); |
---|
| 396 | |
---|
| 397 | // 対象となる$send_idが見つからない |
---|
[20361] | 398 | if (SC_Utils_Ex::isBlank($arrMail)) return; |
---|
[20357] | 399 | |
---|
| 400 | // 送信先リストの取得 |
---|
| 401 | $arrDestinationList = $objQuery->select( |
---|
| 402 | '*', |
---|
| 403 | 'dtb_send_customer', |
---|
| 404 | 'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)', |
---|
| 405 | array($send_id) |
---|
| 406 | ); |
---|
[20540] | 407 | |
---|
[20357] | 408 | // 現在の配信数 |
---|
| 409 | $complete_count = $arrMail['complete_count']; |
---|
| 410 | if(SC_Utils_Ex::isBlank($arrMail)) $complete_count = 0; |
---|
[20540] | 411 | |
---|
[20357] | 412 | foreach ($arrDestinationList as $arrDestination) { |
---|
| 413 | |
---|
| 414 | // 顧客名の変換 |
---|
[20538] | 415 | $customerName = trim($arrDestination['name']); |
---|
| 416 | $subjectBody = preg_replace("/{name}/", $customerName, $arrMail['subject']); |
---|
| 417 | $mailBody = preg_replace("/{name}/", $customerName, $arrMail['body']); |
---|
[20357] | 418 | |
---|
| 419 | $objMail->setItem( |
---|
[20538] | 420 | $arrDestination['email'], |
---|
[20357] | 421 | $subjectBody, |
---|
| 422 | $mailBody, |
---|
[20361] | 423 | $objSite["email03"], // 送信元メールアドレス |
---|
| 424 | $objSite["shop_name"], // 送信元名 |
---|
| 425 | $objSite["email03"], // reply_to |
---|
| 426 | $objSite["email04"], // return_path |
---|
| 427 | $objSite["email04"] // errors_to |
---|
[20357] | 428 | ); |
---|
[20540] | 429 | |
---|
[20357] | 430 | // テキストメール配信の場合 |
---|
| 431 | if ($arrMail["mail_method"] == 2) { |
---|
| 432 | $sendResut = $objMail->sendMail(); |
---|
| 433 | // HTMLメール配信の場合 |
---|
| 434 | } else { |
---|
| 435 | $sendResut = $objMail->sendHtmlMail(); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | // 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入 |
---|
| 439 | if (!$sendResut) { |
---|
| 440 | $sendFlag = '2'; |
---|
| 441 | } else { |
---|
| 442 | // 完了を 1 増やす |
---|
| 443 | $sendFlag = '1'; |
---|
| 444 | $complete_count++; |
---|
| 445 | } |
---|
[20540] | 446 | |
---|
[20357] | 447 | // 送信結果情報を更新 |
---|
| 448 | $objQuery->update('dtb_send_customer', |
---|
| 449 | array('send_flag'=>$sendFlag), |
---|
| 450 | 'send_id = ? AND customer_id = ?', |
---|
| 451 | array($send_id,$arrDestination["customer_id"])); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | // メール全件送信完了後の処理 |
---|
[20361] | 455 | $objQuery->update('dtb_send_history', |
---|
| 456 | array('end_date'=>"now()", 'complete_count'=>$complete_count), |
---|
| 457 | 'send_id = ?', |
---|
| 458 | array($send_id)); |
---|
[20357] | 459 | |
---|
| 460 | // 送信完了 報告メール |
---|
| 461 | $compSubject = date("Y年m月d日H時i分") . " 下記メールの配信が完了しました。"; |
---|
| 462 | // 管理者宛に変更 |
---|
[20361] | 463 | $objMail->setTo($objSite["email03"]); |
---|
[20357] | 464 | $objMail->setSubject($compSubject); |
---|
| 465 | |
---|
| 466 | // テキストメール配信の場合 |
---|
| 467 | if ($arrMail["mail_method"] == 2 ) { |
---|
| 468 | $sendResut = $objMail->sendMail(); |
---|
| 469 | // HTMLメール配信の場合 |
---|
| 470 | } else { |
---|
| 471 | $sendResut = $objMail->sendHtmlMail(); |
---|
| 472 | } |
---|
[20361] | 473 | return; |
---|
[20357] | 474 | } |
---|
[15618] | 475 | } |
---|
| 476 | ?> |
---|