00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006
00007
00014 class oxEmail extends phpmailer
00015 {
00016 public $SMTP_PORT = 25;
00017
00023 protected $_sReminderMailTemplate = "email_owner_reminder_html.tpl";
00024
00030 protected $_sOrderUserTemplate = "email_order_cust_html.tpl";
00031
00037 protected $_sOrderUserPlainTemplate = "email_order_cust_plain.tpl";
00038
00044 protected $_sOrderOwnerTemplate = "email_order_owner_html.tpl";
00045
00051 protected $_sOrderOwnerPlainTemplate = "email_order_owner_plain.tpl";
00052
00053
00054
00060 protected $_sOrderUserSubjectTemplate = "email_order_cust_subj.tpl";
00061
00067 protected $_sOrderOwnerSubjectTemplate = "email_order_owner_subj.tpl";
00068
00074 protected $_sOwnerPricealarmTemplate = "email_pricealarm_owner.tpl";
00075
00081 protected $_oShop = null;
00082
00088 protected $_blInlineImgEmail = null;
00089
00095 protected $_aRecipients = array();
00096
00102 protected $_aReplies = array();
00103
00109 protected $_aAttachments = array();
00110
00114 public function __construct()
00115 {
00116 $myConfig = $this->getConfig();
00117
00118 $this->_setMailerPluginDir();
00119 $this->setSmtp();
00120
00121 $this->setUseInlineImages( true );
00122 $this->setMailWordWrap( 100 );
00123
00124 $this->isHtml( true );
00125 $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00126 }
00127
00139 public function __call( $sMethod, $aArgs )
00140 {
00141 if ( defined( 'OXID_PHP_UNIT' ) ) {
00142 if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00143 $sMethod = str_replace( "UNIT", "_", $sMethod );
00144 }
00145 if ( method_exists( $this, $sMethod)) {
00146 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00147 }
00148 }
00149
00150 throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00151 }
00152
00158 public function getConfig()
00159 {
00160 if ( $this->_oConfig == null ) {
00161 $this->_oConfig = oxConfig::getInstance();
00162 }
00163
00164 return $this->_oConfig;
00165 }
00166
00174 public function setConfig( $oConfig )
00175 {
00176 $this->_oConfig = $oConfig;
00177 }
00178
00186 public function send()
00187 {
00188 $myConfig = $this->getConfig();
00189 $this->setCharSet();
00190
00191 if ( $this->_getUseInlineImages() ) {
00192 $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00193 $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00194 }
00195
00196 $this->_makeOutputProcessing();
00197
00198
00199 if ( $this->getMailer() == 'smtp' ) {
00200 $blRet = $this->_sendMail();
00201
00202
00203 if ( !$blRet ) {
00204 $this->setMailer( 'mail' );
00205 $blRet = $this->_sendMail();
00206 }
00207 } else {
00208
00209 $this->setMailer( 'mail' );
00210 $blRet = $this->_sendMail();
00211 }
00212
00213 if ( !$blRet ) {
00214
00215 $this->_sendMailErrorMsg();
00216 }
00217
00218 return $blRet;
00219 }
00220
00228 public function setSmtp( $oShop = null )
00229 {
00230 $myConfig = $this->getConfig();
00231 $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00232
00233 if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00234 $this->setMailer( "mail" );
00235 return;
00236 }
00237
00238 $this->setHost( $oShop->oxshops__oxsmtp->value );
00239 $this->setMailer( "smtp" );
00240
00241 if ( $oShop->oxshops__oxsmtpuser->value ) {
00242 $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00243 }
00244
00245 if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00246 $this->_setSmtpDebug( true );
00247 }
00248 }
00249
00257 protected function _isValidSmtpHost( $sSmtpHost )
00258 {
00259 $blIsSmtp = false;
00260 if ( $sSmtpHost ) {
00261 if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00262
00263 fclose( $rHandle );
00264 }
00265 }
00266
00267 return $blIsSmtp;
00268 }
00269
00278 public function sendOrderEmailToUser( $oOrder )
00279 {
00280 $myConfig = $this->getConfig();
00281
00282 $sCustHTML = $this->_sOrderUserTemplate;
00283 $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00284
00285
00286 $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00287
00288
00289 $oShop = $this->_getShop();
00290 $this->_setMailParams( $oShop );
00291
00292
00293
00294 $oOrder->oDelSet = $oOrder->getDelSet();
00295
00296
00297 $smarty = oxUtilsView::getInstance()->getSmarty();
00298 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00299 $smarty->assign( "order", $oOrder);
00300 $smarty->assign( "shop", $oShop );
00301 $smarty->assign( "oViewConf", $oShop );
00302 $smarty->assign( "user", $oOrder->getUser() );
00303 $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00304 $smarty->assign( "basket", $oOrder->getBasket() );
00305 $smarty->assign( "payment", $oOrder->getPayment() );
00306 $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00307
00308
00309 $smarty->assign( "iswishlist", true);
00310 $smarty->assign( "isreview", true);
00311
00312 if( $aVoucherList = $oOrder->getVoucherList() ) {
00313 $smarty->assign( "vouchers", $aVoucherList );
00314 }
00315
00316 $oOutputProcessor = oxNew( "oxoutput" );
00317 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00318
00319 foreach ( $aNewSmartyArray as $key => $val ) {
00320 $smarty->assign( $key, $val );
00321 }
00322
00323 $this->setBody( $smarty->fetch( $sCustHTML) );
00324 $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00325
00326
00327 if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00328 $this->setSubject( $smarty->fetch( $this->_sOrderUserSubjectTemplate) );
00329 } else {
00330 $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00331 }
00332
00333 $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00334
00335 $this->setRecipient( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00336 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00337
00338 $blSuccess = $this->send();
00339
00340 return $blSuccess;
00341 }
00342
00351 public function sendOrderEmailToOwner( $oOrder )
00352 {
00353 $myConfig = $this->getConfig();
00354
00355 $sOwnerHTML = $this->_sOrderOwnerTemplate;
00356 $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00357
00358
00359 $this->_clearMailer();
00360
00361
00362 $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00363
00364
00365 $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00366 $this->setFrom( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00367
00368 $iOrderLang = oxLang::getInstance()->getTplLanguage();
00369
00370 $oShop = $this->_getShop();
00371
00372
00373
00374 if ( $oShop->getLanguage() != $iOrderLang ) {
00375 $oShop = $this->_getShop( $iOrderLang );
00376 }
00377
00378 $this->setSmtp( $oShop );
00379
00380
00381 $smarty = oxUtilsView::getInstance()->getSmarty();
00382 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00383 $smarty->assign( "order", $oOrder );
00384 $smarty->assign( "shop", $oShop );
00385 $smarty->assign( "oViewConf", $oShop );
00386 $smarty->assign( "user", $oOrder->getUser() );
00387 $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00388 $smarty->assign( "basket", $oOrder->getBasket() );
00389 $smarty->assign( "payment", $oOrder->getPayment() );
00390
00391
00392 $smarty->assign( "iswishlist", true);
00393
00394 if( $oOrder->getVoucherList() )
00395 $smarty->assign( "vouchers", $oOrder->getVoucherList() );
00396
00397 $oOutputProcessor = oxNew( "oxoutput" );
00398 $aNewSmartyArray = $oOutputProcessor->processViewArray($smarty->get_template_vars(), "oxemail");
00399 foreach ($aNewSmartyArray as $key => $val)
00400 $smarty->assign( $key, $val );
00401
00402
00403 $sPathToTemplate = $myConfig->getTemplateDir(false, $iOrderLang).'/';
00404
00405 $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00406 $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00407
00408
00409
00410 if ( $smarty->template_exists( $this->_sOrderOwnerSubjectTemplate) )
00411 $this->setSubject( $smarty->fetch( $this->_sOrderOwnerSubjectTemplate) );
00412 else
00413 $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00414
00415 $this->setRecipient( $oShop->oxshops__oxowneremail->value, oxLang::getInstance()->translateString("order") );
00416
00417 if ( $oOrder->getUser()->oxuser__oxusername->value != "admin" )
00418 $this->setReplyTo( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00419
00420 $blSuccess = $this->send();
00421
00422
00423 $oRemark = oxNew( "oxremark" );
00424 $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
00425 $oRemark->oxremark__oxparentid = new oxField($oOrder->getUser()->getId(), oxField::T_RAW);
00426 $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
00427 $oRemark->save();
00428
00429
00430 if( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00431 exit();
00432 }
00433
00434 return $blSuccess;
00435 }
00436
00445 public function sendRegisterEmail( $oUser )
00446 {
00447
00448 $oUser = $this->_addUserRegisterEmail( $oUser );
00449
00450
00451 $oShop = $this->_getShop();
00452
00453
00454 $this->_setMailParams( $oShop );
00455
00456
00457 $smarty = oxUtilsView::getInstance()->getSmarty();
00458 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00459 $smarty->assign( "shop", $oShop );
00460 $smarty->assign( "oViewConf", $oShop );
00461 $smarty->assign( "user", $oUser );
00462
00463 $oOutputProcessor = oxNew( "oxoutput" );
00464 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00465
00466 foreach ( $aNewSmartyArray as $key => $val ) {
00467 $smarty->assign( $key, $val );
00468 }
00469
00470 $this->setBody( $smarty->fetch( "email_register_html.tpl") );
00471 $this->setAltBody( $smarty->fetch( "email_register_plain.tpl") );
00472
00473 $this->setSubject( $oShop->oxshops__oxregistersubject->value );
00474
00475 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00476
00477 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00478 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00479
00480 return $this->send();
00481 }
00482
00491 public function sendForgotPwdEmail( $sEmailAddress )
00492 {
00493 $myConfig = $this->getConfig();
00494
00495
00496 $oShop = $this->_getShop();
00497
00498
00499 $oShop = $this->_addForgotPwdEmail( $oShop);
00500
00501
00502 $this->_setMailParams( $oShop );
00503
00504
00505 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and
00506 oxuser.oxusername = '$sEmailAddress' and oxuser.oxpassword != ''
00507 order by oxshopid = '".$oShop->getId()."' desc";
00508
00509 if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00510
00511 $oUser = oxNew( 'oxuser' );
00512 if ( $oUser->load($sOxId) ) {
00513
00514 $smarty = oxUtilsView::getInstance()->getSmarty();
00515 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00516 $smarty->assign( "shop", $oShop );
00517 $smarty->assign( "oViewConf", $oShop );
00518 $smarty->assign( "user", $oUser );
00519
00520 $oOutputProcessor = oxNew( "oxoutput" );
00521 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00522
00523 foreach ( $aNewSmartyArray as $key => $val ) {
00524 $smarty->assign($key, $val);
00525 }
00526
00527 $this->setBody( $smarty->fetch( "email_forgotpwd_html.tpl") );
00528 $this->setAltBody( $smarty->fetch( "email_forgotpwd_plain.tpl") );
00529
00530
00531 $this->setSubject( $oShop->oxshops__oxforgotpwdsubject->value );
00532
00533 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00534
00535 $this->setRecipient( $sEmailAddress, $sFullName );
00536 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00537
00538 return $this->send();
00539 }
00540 }
00541
00542 return false;
00543 }
00544
00555 public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00556 {
00557
00558
00559 $oShop = $this->_getShop();
00560
00561
00562 $this->_setMailParams( $oShop );
00563
00564 $this->setBody( $sMessage );
00565 $this->setSubject( $sSubject );
00566
00567 $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00568 $this->setFrom( $sEmailAddress, "" );
00569 $this->setReplyTo( $sEmailAddress, "" );
00570
00571 return $this->send();
00572 }
00573
00582 public function sendNewsletterDbOptInMail( $oUser )
00583 {
00584
00585
00586 $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00587
00588
00589 $oShop = $this->_getShop();
00590
00591
00592 $this->_setMailParams( $oShop );
00593
00594
00595 $smarty = oxUtilsView::getInstance()->getSmarty();
00596 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00597 $smarty->assign( "shop", $oShop );
00598 $smarty->assign( "oViewConf", $oShop );
00599 $smarty->assign( "user", $oUser );
00600
00601 $oOutputProcessor = oxNew( "oxoutput" );
00602 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00603 foreach ( $aNewSmartyArray as $key => $val ) {
00604 $smarty->assign( $key, $val );
00605 }
00606
00607 $this->setBody( $smarty->fetch("email_newsletteroptin_html.tpl") );
00608 $this->setAltBody( $smarty->fetch( "email_newsletteroptin_plain.tpl") );
00609 $this->setSubject( "Newsletter " . $oShop->oxshops__oxname->getRawValue() );
00610
00611 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00612
00613 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00614 $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00615 $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00616
00617 return $this->send();
00618 }
00619
00629 public function sendNewsletterMail( $oNewsLetter, $oUser )
00630 {
00631
00632 $oShop = $this->_getShop();
00633
00634
00635 $this->_setMailParams( $oShop );
00636
00637 $sBody = $oNewsLetter->getHtmlText();
00638
00639 if ( !empty($sBody) ) {
00640 $this->setBody( $sBody );
00641 $this->setAltBody( $oNewsLetter->getPlainText() );
00642 } else {
00643 $this->isHtml( false );
00644 $this->setBody( $oNewsLetter->getPlainText() );
00645 }
00646
00647 $this->setSubject( $oNewsLetter->oxnewsletter__oxtitle->value );
00648
00649 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00650 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00651 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00652
00653 return $this->send();
00654 }
00655
00665 public function sendSuggestMail( $oParams, $oProduct )
00666 {
00667 $myConfig = $this->getConfig();
00668
00669
00670 $iCurrLang = 0;
00671 $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00672 if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00673 $iCurrLang = $iActShopLang;
00674 }
00675
00676
00677 $oShop = $this->_getShop( $iCurrLang );
00678
00679
00680 if ( $oProduct->getLanguage() != $iCurrLang ) {
00681 $oProduct->setLanguage( $iCurrLang );
00682 $oProduct->load( $oProduct->getId() );
00683 }
00684
00685
00686 $this->setFrom( $oParams->send_email, $oParams->send_name );
00687 $this->setSMTP();
00688
00689
00690 $smarty = oxUtilsView::getInstance()->getSmarty();
00691 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00692 $smarty->assign( "shop", $oShop );
00693 $smarty->assign( "oViewConf", $oShop );
00694 $smarty->assign( "userinfo", $oParams );
00695 $smarty->assign( "product", $oProduct );
00696
00697 $oOutputProcessor = oxNew( "oxoutput" );
00698 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00699
00700 foreach ( $aNewSmartyArray as $key => $val ) {
00701 $smarty->assign( $key, $val );
00702 }
00703
00704 $this->setBody( $smarty->fetch( "email_suggest_html.tpl") );
00705 $this->setAltBody( $smarty->fetch( "email_suggest_plain.tpl") );
00706 $this->setSubject( $oParams->send_subject );
00707
00708 $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00709 $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00710
00711 return $this->send();
00712 }
00713
00722 public function sendSendedNowMail( $oOrder )
00723 {
00724 $myConfig = $this->getConfig();
00725
00726 $iOrderLang = 0;
00727 if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00728 $iOrderLang = $oOrder->oxorder__oxlang->value;
00729 }
00730
00731
00732 $oShop = $this->_getShop( $iOrderLang );
00733
00734
00735 $this->_setMailParams( $oShop );
00736
00737
00738
00739
00740
00741 $smarty = oxUtilsView::getInstance()->getSmarty();
00742 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00743 $smarty->assign( "shop", $oShop );
00744 $smarty->assign( "oViewConf", $oShop );
00745 $smarty->assign( "order", $oOrder );
00746 $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00747
00748
00749 $smarty->assign( "isreview", true);
00750
00751 $oOutputProcessor = oxNew( "oxoutput" );
00752 $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00753
00754 foreach ( $aNewSmartyArray as $key => $val ) {
00755 $smarty->assign( $key, $val );
00756 }
00757
00758
00759 $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00760
00761 $iOldTplLang = oxLang::getInstance()->getTplLanguage();
00762 $iOldBaseLang = oxLang::getInstance()->getTplLanguage();
00763 oxLang::getInstance()->setTplLanguage( $iOrderLang );
00764 oxLang::getInstance()->setBaseLanguage( $iOrderLang );
00765
00766 $smarty->security_settings['INCLUDE_ANY'] = true;
00767
00768
00769 $sPathToTemplate = $myConfig->getTemplateDir(false, $iOrderLang)."/";
00770
00771 $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00772 $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00773 oxLang::getInstance()->setTplLanguage( $iOldTplLang );
00774 oxLang::getInstance()->setBaseLanguage( $iOldBaseLang );
00775
00776 $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00777
00778
00779 $this->setSubject( $oShop->oxshops__oxsendednowsubject->value );
00780
00781 $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00782
00783 $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00784 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00785 return $this->send();
00786 }
00787
00802 public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00803 {
00804
00805
00806
00807
00808
00809
00810
00811 $oShop = $this->_getShop();
00812
00813
00814 $this->_setMailParams( $oShop );
00815
00816 $this->setBody( $sMessage );
00817 $this->setSubject( $sSubject );
00818
00819 $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00820
00821 if ( !$sEmailAddress ) {
00822 $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00823 }
00824
00825 $this->setFrom( $sEmailAddress, "" );
00826 $this->setReplyTo( $sEmailAddress, "" );
00827
00828
00829 $blAttashSucc = true;
00830 $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00831 foreach ( $aAttFiles as $iNum => $sAttFile ) {
00832 if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00833 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00834 } else {
00835 $blAttashSucc = false;
00836 $aError[] = array( 5, $sAttFile );
00837 }
00838 }
00839
00840 if ( !$blAttashSucc ) {
00841 $aError[] = array( 4, "" );
00842 $this->clearAttachments();
00843 return false;
00844 }
00845
00846 $aStatus[] = 3;
00847 $blSend = $this->send();
00848 $this->clearAttachments();
00849
00850 return $blSend;
00851 }
00852
00863 public function sendEmail( $sTo, $sSubject, $sBody )
00864 {
00865
00866 $this->_setMailParams();
00867
00868 if ( is_array($sTo) ) {
00869 foreach ($sTo as $sAddress) {
00870 $this->setRecipient( $sAddress, "" );
00871 $this->setReplyTo( $sAddress, "" );
00872 }
00873 } else {
00874 $this->setRecipient( $sTo, "" );
00875 $this->setReplyTo( $sTo, "" );
00876 }
00877
00878
00879 $this->isHtml( false );
00880
00881 $this->setSubject( $sSubject );
00882 $this->setBody( $sBody );
00883
00884 return $this->send();
00885 }
00886
00894 public function sendStockReminder( $aBasketContents )
00895 {
00896 $myConfig = $this->getConfig();
00897
00898 $aRemindArticles = array();
00899 foreach ( $aBasketContents as $oBasketItem ) {
00900 $oArticle = $oBasketItem->getArticle();
00901
00902 if ( !$oArticle->oxarticles__oxremindactiv->value || $oArticle->oxarticles__oxremindactiv->value > 1 ) {
00903 continue;
00904 }
00905
00906
00907 if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00908 continue;
00909 }
00910
00911 $aRemindArticles[] = $oArticle;
00912 $oArticle->disableReminder();
00913 }
00914
00915
00916 if ( !count( $aRemindArticles ) ) {
00917 return false;
00918 }
00919 $oShop = $this->_getShop();
00920
00921
00922 $this->_setMailParams( $oShop );
00923
00924
00925 $smarty = oxUtilsView::getInstance()->getSmarty();
00926 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00927 $smarty->assign( "shop", $oShop );
00928 $smarty->assign( "oViewConf", $oShop );
00929 $smarty->assign( "articles", $aRemindArticles );
00930
00931
00932 $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00933
00934 $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00935 $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00936 $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00937 $this->setAltBody( "" );
00938 $this->setSubject( oxLang::getInstance()->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00939
00940 return $this->send();
00941 }
00942
00951 public function sendWishlistMail( $oParams )
00952 {
00953 $myConfig = $this->getConfig();
00954
00955 $this->_clearMailer();
00956
00957
00958 $oShop = $this->_getShop();
00959
00960
00961 $this->setFrom( $oParams->send_email, $oParams->send_name );
00962 $this->setSMTP();
00963
00964
00965 $smarty = oxUtilsView::getInstance()->getSmarty();
00966 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00967 $smarty->assign( "shop", $oShop );
00968 $smarty->assign( "oViewConf", $oShop );
00969 $smarty->assign( "userinfo", $oParams );
00970
00971 $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
00972 $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
00973 $this->setSubject( $oParams->send_subject );
00974
00975 $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00976 $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00977
00978 return $this->send();
00979 }
00980
00990 public function sendPriceAlarmNotification( $aParams, $oAlarm )
00991 {
00992 $myConfig = $this->getConfig();
00993
00994 $this->_clearMailer();
00995 $oShop = $this->_getShop();
00996
00997
00998 $this->_setMailParams( $oShop );
00999
01000 $oArticle = oxNew( "oxarticle" );
01001 $oArticle->setSkipAbPrice( true );
01002 $oArticle->load( $aParams['aid'] );
01003
01004 $oCur = $myConfig->getActShopCurrencyObject();
01005
01006 $iAlarmLang = $oShop->getLanguage();
01007
01008
01009 $smarty = oxUtilsView::getInstance()->getSmarty();
01010 $smarty->assign( "shop", $oShop );
01011 $smarty->assign( "oViewConf", $oShop );
01012 $smarty->assign( "product", $oArticle );
01013 $smarty->assign( "email", $aParams['email']);
01014 $smarty->assign( "bidprice", oxLang::getInstance()->formatCurrency($oAlarm->oxpricealarm__oxprice->value, $oCur) );
01015 $smarty->assign( "currency", $oCur );
01016
01017 $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01018 $sSubject = oxLang::getInstance()->translateString('EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value;
01019 $this->setSubject( $sSubject );
01020 $this->setBody( $smarty->fetch($this->_sOwnerPricealarmTemplate) );
01021 $this->setFrom( $aParams['email'], "" );
01022 $this->setReplyTo( $aParams['email'], "" );
01023
01024 return $this->send();
01025 }
01026
01038 protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01039 {
01040 $sBody = $this->getBody();
01041 if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01042
01043 $oFileUtils = oxUtilsFile::getInstance();
01044 $blReSetBody = false;
01045
01046
01047 $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01048 $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01049 $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01050
01051 if (is_array($matches) && count($matches)) {
01052 $aImageCache = array();
01053
01054 foreach ($matches as $aImage) {
01055
01056 $image = $aImage[1];
01057 $sFileName = '';
01058 if ( strpos( $image, $sDynImageDir ) === 0 ) {
01059 $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01060 } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01061 $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01062 } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01063 $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01064 }
01065
01066 if ($sFileName && @is_file($sFileName)) {
01067 $sCId = '';
01068 if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01069 $sCId = $aImageCache[$sFileName];
01070 } else {
01071 $sCId = oxUtilsObject::getInstance()->generateUID();
01072 $sMIME = oxUtils::getInstance()->oxMimeContentType($sFileName);
01073 if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01074 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01075 $aImageCache[$sFileName] = $sCId;
01076 } else {
01077 $sCId = '';
01078 }
01079 }
01080 }
01081 if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01082 if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01083 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01084 $blReSetBody = true;
01085 }
01086 }
01087 }
01088 }
01089 }
01090
01091 if ( $blReSetBody ) {
01092 $this->setBody( $sBody );
01093 }
01094 }
01095 }
01096
01104 public function setSubject( $sSubject = null )
01105 {
01106
01107 $sSubject = str_replace(array('&', '"', ''', '<', '>'), array('&', '"', "'", '<', '>' ), $sSubject);
01108 $this->Subject = $sSubject;
01109 }
01110
01116 public function getSubject()
01117 {
01118 return $this->Subject;
01119 }
01120
01130 public function setBody( $sBody = null, $blClearSid = true )
01131 {
01132 if ( $blClearSid ) {
01133 $sBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&shp=" . $this->getConfig()->getShopId(), $sBody);
01134 }
01135
01136 $this->Body = $sBody;
01137 }
01138
01144 public function getBody()
01145 {
01146 return $this->Body;
01147 }
01148
01158 public function setAltBody( $sAltBody = null, $blClearSid = true )
01159 {
01160 if ( $blClearSid ) {
01161 $sAltBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&shp=" . $this->getConfig()->getShopId(), $sAltBody);
01162 }
01163
01164
01165 $sAltBody = str_replace(array('&', '"', ''', '<', '>'), array('&', '"', "'", '<', '>' ), $sAltBody);
01166 $this->AltBody = $sAltBody;
01167 }
01168
01174 public function getAltBody()
01175 {
01176 return $this->AltBody;
01177 }
01178
01187 public function setRecipient( $sAddress = null, $sName = null )
01188 {
01189
01190 $this->_aRecipients[] = array( $sAddress, $sName );
01191
01192 parent::AddAddress($sAddress, $sName );
01193 }
01194
01202 public function getRecipient()
01203 {
01204 return $this->_aRecipients;
01205 }
01206
01213 public function clearAllRecipients()
01214 {
01215 $this->_aRecipients = array();
01216 parent::clearAllRecipients();
01217 }
01218
01230 public function setReplyTo( $sEmail = null, $sName = null )
01231 {
01232 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01233 $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01234 }
01235
01236 $this->_aReplies[] = array( $sEmail, $sName );
01237 parent::AddReplyTo( $sEmail, $sName );
01238 }
01239
01245 public function getReplyTo()
01246 {
01247 return $this->_aReplies;
01248 }
01249
01255 public function clearReplyTos()
01256 {
01257 $this->_aReplies = array();
01258 parent::clearReplyTos();
01259 }
01260
01269 public function setFrom( $sFromAdress = null, $sFromName = null )
01270 {
01271
01272
01273
01274 $this->From = substr($sFromAdress, 0, 150);
01275 $this->FromName = substr($sFromName, 0, 150);
01276 }
01277
01283 public function getFrom()
01284 {
01285 return $this->From;
01286 }
01287
01293 public function getFromName()
01294 {
01295 return $this->FromName;
01296 }
01297
01306 public function setCharSet( $sCharSet = null )
01307 {
01308 if ( !empty($sCharSet) ) {
01309 $this->CharSet = $sCharSet;
01310 } else {
01311 $this->CharSet = oxLang::getInstance()->translateString("charset");
01312 }
01313 }
01314
01320 public function getCharSet()
01321 {
01322 return $this->CharSet;
01323 }
01324
01332 public function setMailer( $sMailer = null )
01333 {
01334 $this->Mailer = $sMailer;
01335 }
01336
01342 public function getMailer()
01343 {
01344 return $this->Mailer;
01345 }
01346
01354 public function setHost( $sHost = null )
01355 {
01356 $this->Host = $sHost;
01357 }
01358
01364 public function getErrorInfo()
01365 {
01366 return $this->ErrorInfo;
01367 }
01368
01377 public function setMailWordWrap( $iWordWrap = null )
01378 {
01379 $this->WordWrap = $iWordWrap;
01380 }
01381
01389 public function setUseInlineImages( $blUseImages = null )
01390 {
01391 $this->_blInlineImgEmail = $blUseImages;
01392 }
01393
01404 public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01405 {
01406 $sFullPath = $sAttPath . $sAttFile;
01407
01408 $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01409 return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01410 }
01411
01423 public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01424 {
01425 $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01426 return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01427 }
01428
01434 public function getAttachments()
01435 {
01436 return $this->_aAttachments;
01437 }
01438
01444 public function clearAttachments()
01445 {
01446 $this->_aAttachments = array();
01447 return parent::ClearAttachments();
01448 }
01449
01459 public function headerLine($sName, $sValue)
01460 {
01461 if (stripos($sName, 'X-') !== false) {
01462 return;
01463 }
01464 return parent::headerLine($sName, $sValue);
01465 }
01466
01472 protected function _getUseInlineImages()
01473 {
01474 return $this->_blInlineImgEmail;
01475 }
01476
01482 protected function _sendMailErrorMsg()
01483 {
01484
01485 $sToAdress = "";
01486 $sToName = "";
01487
01488 $aRecipients = $this->getRecipient();
01489
01490 $sOwnerMessage = "Error sending eMail(". $this->getSubject().") to: \n\n";
01491
01492 foreach ( $aRecipients as $aEMail ) {
01493 $sOwnerMessage .= $aEMail[0];
01494 $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01495 $sOwnerMessage .= " \n ";
01496 }
01497 $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01498
01499
01500 $oShop = $this->_getShop();
01501
01502 $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01503
01504 return $blRet;
01505 }
01506
01516 protected function _addUserInfoOrderEMail( $oOrder )
01517 {
01518 return $oOrder;
01519 }
01520
01530 protected function _addUserRegisterEmail( $oUser )
01531 {
01532 return $oUser;
01533 }
01534
01544 protected function _addForgotPwdEmail( $oShop )
01545 {
01546 return $oShop;
01547 }
01548
01558 protected function _addNewsletterDbOptInMail( $oUser )
01559 {
01560 return $oUser;
01561 }
01562
01568 protected function _clearMailer()
01569 {
01570 $this->clearAllRecipients();
01571 $this->clearReplyTos();
01572 $this->clearAttachments();
01573
01574
01575 $this->error_count = 0;
01576 $this->ErrorInfo = '';
01577 }
01578
01586 protected function _setMailParams( $oShop = null )
01587 {
01588 $this->_clearMailer();
01589
01590 if ( !$oShop ) {
01591 $oShop = $this->_getShop();
01592 }
01593
01594 $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01595 $this->setSmtp( $oShop );
01596 }
01597
01606 protected function _getShop( $iLangId = null )
01607 {
01608 $myConfig = $this->getConfig();
01609 if ( !isset($iLangId) ) {
01610 $iLangId = 0;
01611 $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01612 if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01613 $iLangId = $iActShopLang;
01614 }
01615 }
01616 if ( isset($this->_oShop) && $this->_oShop ) {
01617
01618
01619 if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01620 return $this->_oShop;
01621 }
01622 }
01623
01624 $this->_oShop = oxNew( 'oxshop' );
01625
01626 $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01627
01628 $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01629
01630 $oView = $myConfig->getActiveView();
01631 $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01632
01633 return $this->_oShop;
01634 }
01635
01644 protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01645 {
01646 $this->SMTPAuth = true;
01647 $this->Username = $sUserName;
01648 $this->Password = $sUserPassword;
01649 }
01650
01658 protected function _setSmtpDebug( $blDebug = null )
01659 {
01660 $this->SMTPDebug = $blDebug;
01661 }
01662
01668 protected function _setMailerPluginDir()
01669 {
01670 $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01671 }
01672
01679 protected function _makeOutputProcessing()
01680 {
01681 $oOutput = oxNew( "oxoutput" );
01682 $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01683 $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01684 $oOutput->processEmail( $this );
01685 }
01686
01692 protected function _sendMail()
01693 {
01694 return parent::send();
01695 }
01696 }