oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006 
00007 
00013 class oxEmail extends phpmailer
00014 {
00020     public $SMTP_PORT = 25;
00021 
00027     protected $_sReminderMailTemplate = "email_owner_reminder_html.tpl";
00028 
00034     protected $_sOrderUserTemplate          = "email_order_cust_html.tpl";
00035 
00041     protected $_sOrderUserPlainTemplate     = "email_order_cust_plain.tpl";
00042 
00048     protected $_sOrderOwnerTemplate         = "email_order_owner_html.tpl";
00049 
00055     protected $_sOrderOwnerPlainTemplate    = "email_order_owner_plain.tpl";
00056 
00057     // #586A - additional templates for more customizable subjects
00058 
00064     protected $_sOrderUserSubjectTemplate   = "email_order_cust_subj.tpl";
00065 
00071     protected $_sOrderOwnerSubjectTemplate  = "email_order_owner_subj.tpl";
00072 
00078     protected $_sOwnerPricealarmTemplate    = "email_pricealarm_owner.tpl";
00079 
00085     protected $_oShop = null;
00086 
00092     protected $_blInlineImgEmail = null;
00093 
00099     protected $_aRecipients = array();
00100 
00106     protected $_aReplies = array();
00107 
00113     protected $_aAttachments = array();
00114 
00118     public function __construct()
00119     {
00120         $myConfig = $this->getConfig();
00121 
00122         $this->_setMailerPluginDir();
00123         $this->setSmtp();
00124 
00125         $this->setUseInlineImages( true );
00126         $this->setMailWordWrap( 100 );
00127 
00128         $this->isHtml( true );
00129         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00130     }
00131 
00143     public function __call( $sMethod, $aArgs )
00144     {
00145         if ( defined( 'OXID_PHP_UNIT' ) ) {
00146             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00147                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00148             }
00149             if ( method_exists( $this, $sMethod)) {
00150                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00151             }
00152         }
00153 
00154         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00155     }
00156 
00162     public function getConfig()
00163     {
00164         if ( $this->_oConfig == null ) {
00165             $this->_oConfig = oxConfig::getInstance();
00166         }
00167 
00168         return $this->_oConfig;
00169     }
00170 
00178     public function setConfig( $oConfig )
00179     {
00180         $this->_oConfig = $oConfig;
00181     }
00182 
00190     public function send()
00191     {
00192         $myConfig = $this->getConfig();
00193         $this->setCharSet();
00194 
00195         if ( $this->_getUseInlineImages() ) {
00196             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00197                                    $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00198         }
00199 
00200         $this->_makeOutputProcessing();
00201 
00202         // try to send mail via SMTP
00203         if ( $this->getMailer() == 'smtp' ) {
00204             $blRet = $this->_sendMail();
00205 
00206             // if sending failed, try to send via mail()
00207             if ( !$blRet ) {
00208                 $this->setMailer( 'mail' );
00209                 $blRet = $this->_sendMail();
00210             }
00211         } else {
00212             // sending mail via mail()
00213             $this->setMailer( 'mail' );
00214             $blRet = $this->_sendMail();
00215         }
00216 
00217         if ( !$blRet ) {
00218             // failed sending, giving up, trying to send notification to shop owner
00219             $this->_sendMailErrorMsg();
00220         }
00221 
00222         return $blRet;
00223     }
00224 
00232     public function setSmtp( $oShop = null )
00233     {
00234         $myConfig = $this->getConfig();
00235         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00236 
00237         if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00238             $this->setMailer( "mail" );
00239             return;
00240         }
00241 
00242         $this->setHost( $oShop->oxshops__oxsmtp->value );
00243         $this->setMailer( "smtp" );
00244 
00245         if ( $oShop->oxshops__oxsmtpuser->value ) {
00246             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00247         }
00248 
00249         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00250             $this->_setSmtpDebug( true );
00251         }
00252     }
00253 
00261     protected function _isValidSmtpHost( $sSmtpHost )
00262     {
00263         $blIsSmtp = false;
00264         if ( $sSmtpHost ) {
00265             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00266                 // closing connection ..
00267                 fclose( $rHandle );
00268             }
00269         }
00270 
00271         return $blIsSmtp;
00272     }
00273 
00282     public function sendOrderEmailToUser( $oOrder )
00283     {
00284         $myConfig = $this->getConfig();
00285 
00286         $sCustHTML  = $this->_sOrderUserTemplate;
00287         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00288 
00289         // add user defined stuff if there is any
00290         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00291 
00292         //set mail params (from, fromName, smtp)
00293         $oShop = $this->_getShop();
00294         $this->_setMailParams( $oShop );
00295 
00296         // P
00297         // setting some deprecated variables
00298         $oOrder->oDelSet = $oOrder->getDelSet();
00299 
00300         // create messages
00301         $smarty = oxUtilsView::getInstance()->getSmarty();
00302         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00303         $smarty->assign( "order", $oOrder);
00304         $smarty->assign( "shop", $oShop );
00305         $smarty->assign( "oViewConf", $oShop );
00306         $smarty->assign( "user", $oOrder->getUser() );
00307         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00308         $smarty->assign( "basket", $oOrder->getBasket() );
00309         $smarty->assign( "payment", $oOrder->getPayment() );
00310         $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00311 
00312         //deprecated vars
00313         $smarty->assign( "iswishlist", true);
00314         $smarty->assign( "isreview", true);
00315 
00316         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00317             $smarty->assign( "vouchers", $aVoucherList );
00318         }
00319 
00320         $oOutputProcessor = oxNew( "oxoutput" );
00321         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00322 
00323         foreach ( $aNewSmartyArray as $key => $val ) {
00324             $smarty->assign( $key, $val );
00325         }
00326 
00327         $this->setBody( $smarty->fetch( $sCustHTML) );
00328         $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00329 
00330         // #586A
00331         if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00332             $this->setSubject( $smarty->fetch( $this->_sOrderUserSubjectTemplate) );
00333         } else {
00334             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00335         }
00336 
00337         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00338 
00339         $this->setRecipient( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00340         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00341 
00342         $blSuccess = $this->send();
00343 
00344         return $blSuccess;
00345     }
00346 
00355     public function sendOrderEmailToOwner( $oOrder )
00356     {
00357         $myConfig = $this->getConfig();
00358 
00359         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00360         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00361 
00362         // cleanup
00363         $this->_clearMailer();
00364 
00365         // add user defined stuff if there is any
00366         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00367 
00368         // send confirmation to shop owner
00369         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00370         $this->setFrom( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00371 
00372         $oLang = oxLang::getInstance();
00373         $iOrderLang = $oLang->getTplLanguage();
00374 
00375         $oShop = $this->_getShop();
00376 
00377         // if running shop language is different from admin lang. set in config
00378         // we have to load shop in config language
00379         if ( $oShop->getLanguage() != $iOrderLang ) {
00380             $oShop = $this->_getShop( $iOrderLang );
00381         }
00382 
00383         $this->setSmtp( $oShop );
00384 
00385         // create messages
00386         $smarty = oxUtilsView::getInstance()->getSmarty();
00387         $smarty->assign( "charset", $oLang->translateString("charset"));
00388         $smarty->assign( "order", $oOrder );
00389         $smarty->assign( "shop", $oShop );
00390         $smarty->assign( "oViewConf", $oShop );
00391         $smarty->assign( "user", $oOrder->getUser() );
00392         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00393         $smarty->assign( "basket", $oOrder->getBasket() );
00394         $smarty->assign( "payment", $oOrder->getPayment() );
00395 
00396         //deprecated var
00397         $smarty->assign( "iswishlist", true);
00398 
00399         if( $oOrder->getVoucherList() )
00400             $smarty->assign( "vouchers", $oOrder->getVoucherList() );
00401 
00402         $oOutputProcessor = oxNew( "oxoutput" );
00403         $aNewSmartyArray = $oOutputProcessor->processViewArray($smarty->get_template_vars(), "oxemail");
00404         foreach ($aNewSmartyArray as $key => $val)
00405             $smarty->assign( $key, $val );
00406 
00407         //path to admin message template file
00408         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00409 
00410         $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00411         $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00412 
00413         //Sets subject to email
00414         // #586A
00415         if ( $smarty->template_exists( $this->_sOrderOwnerSubjectTemplate) )
00416             $this->setSubject( $smarty->fetch( $this->_sOrderOwnerSubjectTemplate) );
00417         else
00418             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00419 
00420         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00421 
00422         if ( $oOrder->getUser()->oxuser__oxusername->value != "admin" )
00423             $this->setReplyTo( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00424 
00425         $blSuccess = $this->send();
00426 
00427         // add user history
00428         $oRemark = oxNew( "oxremark" );
00429         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00430         $oRemark->oxremark__oxparentid  = new oxField($oOrder->getUser()->getId(), oxField::T_RAW);
00431         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00432         $oRemark->save();
00433 
00434 
00435         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00436             exit();
00437         }
00438 
00439         return $blSuccess;
00440     }
00441 
00450     public function sendRegisterEmail( $oUser )
00451     {
00452         // add user defined stuff if there is any
00453         $oUser = $this->_addUserRegisterEmail( $oUser );
00454 
00455         // shop info
00456         $oShop = $this->_getShop();
00457 
00458         //set mail params (from, fromName, smtp )
00459         $this->_setMailParams( $oShop );
00460 
00461         // create messages
00462         $smarty = oxUtilsView::getInstance()->getSmarty();
00463         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00464         $smarty->assign( "shop", $oShop );
00465         $smarty->assign( "oViewConf", $oShop );
00466         $smarty->assign( "user", $oUser );
00467 
00468         $oOutputProcessor = oxNew( "oxoutput" );
00469         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00470 
00471         foreach ( $aNewSmartyArray as $key => $val ) {
00472             $smarty->assign( $key, $val );
00473         }
00474 
00475         $this->setBody( $smarty->fetch( "email_register_html.tpl") );
00476         $this->setAltBody( $smarty->fetch( "email_register_plain.tpl") );
00477 
00478         $this->setSubject( $oShop->oxshops__oxregistersubject->value );
00479 
00480         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00481 
00482         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00483         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00484 
00485         return $this->send();
00486     }
00487 
00496     public function sendForgotPwdEmail( $sEmailAddress )
00497     {
00498         $myConfig = $this->getConfig();
00499 
00500         // shop info
00501         $oShop = $this->_getShop();
00502 
00503         // add user defined stuff if there is any
00504         $oShop = $this->_addForgotPwdEmail( $oShop);
00505 
00506         //set mail params (from, fromName, smtp)
00507         $this->_setMailParams( $oShop );
00508 
00509         // user
00510         $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and
00511                     oxuser.oxusername = '$sEmailAddress' and oxuser.oxpassword != ''
00512                     order by oxshopid = '".$oShop->getId()."' desc";
00513 
00514         if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00515 
00516             $oUser = oxNew( 'oxuser' );
00517             if ( $oUser->load($sOxId) ) {
00518                 // create messages
00519                 $smarty = oxUtilsView::getInstance()->getSmarty();
00520                 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00521                 $smarty->assign( "shop", $oShop );
00522                 $smarty->assign( "oViewConf", $oShop );
00523                 $smarty->assign( "user", $oUser );
00524 
00525                 $oOutputProcessor = oxNew( "oxoutput" );
00526                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00527 
00528                 foreach ( $aNewSmartyArray as $key => $val ) {
00529                     $smarty->assign($key, $val);
00530                 }
00531 
00532                 $this->setBody( $smarty->fetch( "email_forgotpwd_html.tpl") );
00533                 $this->setAltBody( $smarty->fetch( "email_forgotpwd_plain.tpl") );
00534 
00535                 //sets subject of email
00536                 $this->setSubject( $oShop->oxshops__oxforgotpwdsubject->value );
00537 
00538                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00539 
00540                 $this->setRecipient( $sEmailAddress, $sFullName );
00541                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00542 
00543                 return $this->send();
00544             }
00545         }
00546 
00547         return false;
00548     }
00549 
00560     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00561     {
00562 
00563         // shop info
00564         $oShop = $this->_getShop();
00565 
00566         //set mail params (from, fromName, smtp)
00567         $this->_setMailParams( $oShop );
00568 
00569         $this->setBody( $sMessage );
00570         $this->setSubject( $sSubject );
00571 
00572         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00573         $this->setFrom( $sEmailAddress, "" );
00574         $this->setReplyTo( $sEmailAddress, "" );
00575 
00576         return $this->send();
00577     }
00578 
00587     public function sendNewsletterDbOptInMail( $oUser )
00588     {
00589 
00590         // add user defined stuff if there is any
00591         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00592 
00593         // shop info
00594         $oShop = $this->_getShop();
00595 
00596         //set mail params (from, fromName, smtp)
00597         $this->_setMailParams( $oShop );
00598 
00599         // create messages
00600         $smarty = oxUtilsView::getInstance()->getSmarty();
00601         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00602         $smarty->assign( "shop", $oShop );
00603         $smarty->assign( "oViewConf", $oShop );
00604         $smarty->assign( "user", $oUser );
00605 
00606         $oOutputProcessor = oxNew( "oxoutput" );
00607         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00608         foreach ( $aNewSmartyArray as $key => $val ) {
00609             $smarty->assign( $key, $val );
00610         }
00611 
00612         $this->setBody( $smarty->fetch("email_newsletteroptin_html.tpl") );
00613         $this->setAltBody( $smarty->fetch( "email_newsletteroptin_plain.tpl") );
00614         $this->setSubject( "Newsletter " . $oShop->oxshops__oxname->getRawValue() );
00615 
00616         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00617 
00618         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00619         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00620         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00621 
00622         return $this->send();
00623     }
00624 
00634     public function sendNewsletterMail( $oNewsLetter, $oUser )
00635     {
00636         // shop info
00637         $oShop = $this->_getShop();
00638 
00639         //set mail params (from, fromName, smtp)
00640         $this->_setMailParams( $oShop );
00641 
00642         $sBody = $oNewsLetter->getHtmlText();
00643 
00644         if ( !empty($sBody) ) {
00645             $this->setBody( $sBody );
00646             $this->setAltBody( $oNewsLetter->getPlainText() );
00647         } else {
00648             $this->isHtml( false );
00649             $this->setBody( $oNewsLetter->getPlainText() );
00650         }
00651 
00652         $this->setSubject( $oNewsLetter->oxnewsletter__oxtitle->value );
00653 
00654         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00655         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00656         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00657 
00658         return $this->send();
00659     }
00660 
00670     public function sendSuggestMail( $oParams, $oProduct )
00671     {
00672         $myConfig = $this->getConfig();
00673 
00674         //sets language of shop
00675         $iCurrLang = 0;
00676         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00677         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00678             $iCurrLang = $iActShopLang;
00679         }
00680 
00681         // shop info
00682         $oShop = $this->_getShop( $iCurrLang );
00683 
00684         //sets language to article
00685         if ( $oProduct->getLanguage() != $iCurrLang ) {
00686             $oProduct->setLanguage( $iCurrLang );
00687             $oProduct->load( $oProduct->getId() );
00688         }
00689 
00690         // mailer stuff
00691         $this->setFrom( $oParams->send_email, $oParams->send_name );
00692         $this->setSMTP();
00693 
00694         // create messages
00695         $smarty = oxUtilsView::getInstance()->getSmarty();
00696         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00697         $smarty->assign( "shop", $oShop );
00698         $smarty->assign( "oViewConf", $oShop );
00699         $smarty->assign( "userinfo", $oParams );
00700         $smarty->assign( "product", $oProduct );
00701 
00702         $oOutputProcessor = oxNew( "oxoutput" );
00703         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00704 
00705         foreach ( $aNewSmartyArray as $key => $val ) {
00706             $smarty->assign( $key, $val );
00707         }
00708 
00709         $this->setBody( $smarty->fetch( "email_suggest_html.tpl") );
00710         $this->setAltBody( $smarty->fetch( "email_suggest_plain.tpl") );
00711         $this->setSubject( $oParams->send_subject );
00712 
00713         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00714         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00715 
00716         return $this->send();
00717     }
00718 
00727     public function sendSendedNowMail( $oOrder )
00728     {
00729         $myConfig = $this->getConfig();
00730 
00731         $iOrderLang = 0;
00732         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00733             $iOrderLang = $oOrder->oxorder__oxlang->value;
00734         }
00735 
00736         // shop info
00737         $oShop = $this->_getShop( $iOrderLang );
00738 
00739         //set mail params (from, fromName, smtp)
00740         $this->_setMailParams( $oShop );
00741 
00742         //override default wrap
00743         //$this->setMailWordWrap( 0 );
00744 
00745         //create messages
00746         $oLang = oxLang::getInstance();
00747         $smarty = oxUtilsView::getInstance()->getSmarty();
00748         $smarty->assign( "charset", $oLang->translateString("charset"));
00749         $smarty->assign( "shop", $oShop );
00750         $smarty->assign( "oViewConf", $oShop );
00751         $smarty->assign( "order", $oOrder );
00752         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00753 
00754         //deprecated var
00755         $smarty->assign( "isreview", true);
00756 
00757         $oOutputProcessor = oxNew( "oxoutput" );
00758         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00759 
00760         foreach ( $aNewSmartyArray as $key => $val ) {
00761             $smarty->assign( $key, $val );
00762         }
00763 
00764         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00765         $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00766         //V send email in order language
00767         $iOldTplLang = $oLang->getTplLanguage();
00768         $iOldBaseLang = $oLang->getTplLanguage();
00769         $oLang->setTplLanguage( $iOrderLang );
00770         $oLang->setBaseLanguage( $iOrderLang );
00771 
00772         $smarty->security_settings['INCLUDE_ANY'] = true;
00773 
00774         //Sets path to template file
00775         $sPathToTemplate = $myConfig->getTemplateDir(false)."/";
00776 
00777         $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00778         $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00779         $oLang->setTplLanguage( $iOldTplLang );
00780         $oLang->setBaseLanguage( $iOldBaseLang );
00781         // set it back
00782         $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00783 
00784         //Sets subject to email
00785         $this->setSubject( $oShop->oxshops__oxsendednowsubject->value );
00786 
00787         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00788 
00789         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00790         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00791         return $this->send();
00792     }
00793 
00808     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00809     {
00810 
00811         /* P
00812         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00813         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00814         */
00815 
00816         // shop info
00817         $oShop = $this->_getShop();
00818 
00819         //set mail params (from, fromName, smtp)
00820         $this->_setMailParams( $oShop );
00821 
00822         $this->setBody( $sMessage );
00823         $this->setSubject( $sSubject );
00824 
00825         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00826 
00827         if ( !$sEmailAddress ) {
00828             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00829         }
00830 
00831         $this->setFrom( $sEmailAddress, "" );
00832         $this->setReplyTo( $sEmailAddress, "" );
00833 
00834         //attaching files
00835         $blAttashSucc = true;
00836         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00837         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00838             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00839                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00840             } else {
00841                 $blAttashSucc = false;
00842                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00843             }
00844         }
00845 
00846         if ( !$blAttashSucc ) {
00847             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00848             $this->clearAttachments();
00849             return false;
00850         }
00851 
00852         $aStatus[] = 3;     //"Mailing backup files ...";
00853         $blSend = $this->send();
00854         $this->clearAttachments();
00855 
00856         return $blSend;
00857     }
00858 
00869     public function sendEmail( $sTo, $sSubject, $sBody )
00870     {
00871         //set mail params (from, fromName, smtp)
00872         $this->_setMailParams();
00873 
00874         if ( is_array($sTo) ) {
00875             foreach ($sTo as $sAddress) {
00876                 $this->setRecipient( $sAddress, "" );
00877                 $this->setReplyTo( $sAddress, "" );
00878             }
00879         } else {
00880             $this->setRecipient( $sTo, "" );
00881             $this->setReplyTo( $sTo, "" );
00882         }
00883 
00884         //may be changed later
00885         $this->isHtml( false );
00886 
00887         $this->setSubject( $sSubject );
00888         $this->setBody( $sBody );
00889 
00890         return $this->send();
00891     }
00892 
00900     public function sendStockReminder( $aBasketContents )
00901     {
00902         $myConfig = $this->getConfig();
00903 
00904         $aRemindArticles = array();
00905         foreach ( $aBasketContents as $oBasketItem ) {
00906             $oArticle = $oBasketItem->getArticle();
00907              // reminder not set
00908             if ( !$oArticle->oxarticles__oxremindactive->value || $oArticle->oxarticles__oxremindactive->value > 1 ) {
00909                 continue;
00910             }
00911 
00912             // number or articles available is more
00913             if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00914                 continue;
00915             }
00916 
00917             $aRemindArticles[] = $oArticle;
00918             $oArticle->disableReminder();
00919         }
00920 
00921         // nothing to remind ...
00922         if ( !count( $aRemindArticles ) ) {
00923             return false;
00924         }
00925         $oShop = $this->_getShop();
00926 
00927         //set mail params (from, fromName, smtp... )
00928         $this->_setMailParams( $oShop );
00929         $oLang = oxLang::getInstance();
00930 
00931 
00932         $smarty = oxUtilsView::getInstance()->getSmarty();
00933         $smarty->assign( "charset", $oLang->translateString("charset"));
00934         $smarty->assign( "shop", $oShop );
00935         $smarty->assign( "oViewConf", $oShop );
00936         $smarty->assign( "articles", $aRemindArticles );
00937 
00938         //path to admin message template file
00939         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00940 
00941         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00942         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00943         $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00944         $this->setAltBody( "" );
00945         $this->setSubject( $oLang->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00946 
00947         return $this->send();
00948     }
00949 
00958     public function sendWishlistMail( $oParams )
00959     {
00960         $myConfig = $this->getConfig();
00961 
00962         $this->_clearMailer();
00963 
00964         // shop info
00965         $oShop = $this->_getShop();
00966 
00967         // mailer stuff
00968         $this->setFrom( $oParams->send_email, $oParams->send_name );
00969         $this->setSMTP();
00970 
00971         // create messages
00972         $smarty = oxUtilsView::getInstance()->getSmarty();
00973         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00974         $smarty->assign( "shop", $oShop );
00975         $smarty->assign( "oViewConf", $oShop );
00976         $smarty->assign( "userinfo", $oParams );
00977 
00978         $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
00979         $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
00980         $this->setSubject( $oParams->send_subject );
00981 
00982         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00983         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00984 
00985         return $this->send();
00986     }
00987 
00997     public function sendPriceAlarmNotification( $aParams, $oAlarm )
00998     {
00999         $this->_clearMailer();
01000         $oShop = $this->_getShop();
01001 
01002         //set mail params (from, fromName, smtp)
01003         $this->_setMailParams( $oShop );
01004 
01005         $iAlarmLang = $oShop->getLanguage();
01006 
01007         $oArticle = oxNew( "oxarticle" );
01008         $oArticle->setSkipAbPrice( true );
01009         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01010 
01011         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01012         $oLang = oxLang::getInstance();
01013 
01014         // create messages
01015         $smarty = oxUtilsView::getInstance()->getSmarty();
01016         $smarty->assign( "shop", $oShop );
01017         $smarty->assign( "oViewConf", $oShop );
01018         $smarty->assign( "product", $oArticle );
01019         $smarty->assign( "email", $aParams['email']);
01020         $smarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01021         $smarty->assign( "currency", $oCur );
01022 
01023         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01024         $sSubject = $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value;
01025         $this->setSubject( $sSubject );
01026         $this->setBody( $smarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01027         $this->setFrom( $aParams['email'], "" );
01028         $this->setReplyTo( $aParams['email'], "" );
01029 
01030         return $this->send();
01031     }
01032 
01044     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01045     {
01046         $sBody = $this->getBody();
01047         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01048 
01049             $oFileUtils = oxUtilsFile::getInstance();
01050             $blReSetBody = false;
01051 
01052             // preparing imput
01053             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01054             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01055             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01056 
01057             if (is_array($matches) && count($matches)) {
01058                 $aImageCache = array();
01059                 $myUtils = oxUtils::getInstance();
01060                 $myUtilsObject = oxUtilsObject::getInstance();
01061 
01062                 foreach ($matches as $aImage) {
01063 
01064                     $image = $aImage[1];
01065                     $sFileName = '';
01066                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01067                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01068                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01069                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01070                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01071                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01072                     }
01073 
01074                     if ($sFileName && @is_file($sFileName)) {
01075                         $sCId = '';
01076                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01077                             $sCId = $aImageCache[$sFileName];
01078                         } else {
01079                             $sCId = $myUtilsObject->generateUID();
01080                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01081                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01082                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01083                                     $aImageCache[$sFileName] = $sCId;
01084                                 } else {
01085                                     $sCId = '';
01086                                 }
01087                             }
01088                         }
01089                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01090                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01091                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01092                                 $blReSetBody = true;
01093                             }
01094                         }
01095                     }
01096                 }
01097             }
01098 
01099             if ( $blReSetBody ) {
01100                 $this->setBody( $sBody );
01101             }
01102         }
01103     }
01104 
01112     public function setSubject( $sSubject = null )
01113     {
01114         // A. HTML entites in subjects must be replaced
01115         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01116         $this->Subject = $sSubject;
01117     }
01118 
01124     public function getSubject()
01125     {
01126         return $this->Subject;
01127     }
01128 
01138     public function setBody( $sBody = null, $blClearSid = true )
01139     {
01140         if ( $blClearSid ) {
01141             $sBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01142         }
01143 
01144         $this->Body = $sBody;
01145     }
01146 
01152     public function getBody()
01153     {
01154         return $this->Body;
01155     }
01156 
01166     public function setAltBody( $sAltBody = null, $blClearSid = true )
01167     {
01168         if ( $blClearSid ) {
01169             $sAltBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01170         }
01171 
01172         // A. alt body is used for plain text emails so we should eliminate HTML entities
01173         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01174         $this->AltBody = $sAltBody;
01175     }
01176 
01182     public function getAltBody()
01183     {
01184         return $this->AltBody;
01185     }
01186 
01195     public function setRecipient( $sAddress = null, $sName = null )
01196     {
01197         // copying values as original class does not allow to access recipients array
01198         $this->_aRecipients[] = array( $sAddress, $sName );
01199 
01200         parent::AddAddress($sAddress, $sName );
01201     }
01202 
01210     public function getRecipient()
01211     {
01212         return $this->_aRecipients;
01213     }
01214 
01221     public function clearAllRecipients()
01222     {
01223         $this->_aRecipients = array();
01224         parent::clearAllRecipients();
01225     }
01226 
01238     public function setReplyTo( $sEmail = null, $sName = null )
01239     {
01240         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01241             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01242         }
01243 
01244         $this->_aReplies[] = array( $sEmail, $sName );
01245         parent::AddReplyTo( $sEmail, $sName );
01246     }
01247 
01253     public function getReplyTo()
01254     {
01255         return $this->_aReplies;
01256     }
01257 
01263     public function clearReplyTos()
01264     {
01265         $this->_aReplies = array();
01266         parent::clearReplyTos();
01267     }
01268 
01277     public function setFrom( $sFromAdress = null, $sFromName = null )
01278     {
01279         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01280         // this is simple but must work
01281         // dodger Task #1532 field "From" in emails from shops
01282         $this->From     = substr($sFromAdress, 0, 150);
01283         $this->FromName = substr($sFromName, 0, 150);
01284     }
01285 
01291     public function getFrom()
01292     {
01293         return $this->From;
01294     }
01295 
01301     public function getFromName()
01302     {
01303         return $this->FromName;
01304     }
01305 
01314     public function setCharSet( $sCharSet = null )
01315     {
01316         if ( !empty($sCharSet) ) {
01317             $this->CharSet = $sCharSet;
01318         } else {
01319             $this->CharSet = oxLang::getInstance()->translateString("charset");
01320         }
01321     }
01322 
01328     public function getCharSet()
01329     {
01330         return $this->CharSet;
01331     }
01332 
01340     public function setMailer( $sMailer = null )
01341     {
01342         $this->Mailer = $sMailer;
01343     }
01344 
01350     public function getMailer()
01351     {
01352         return $this->Mailer;
01353     }
01354 
01362     public function setHost( $sHost = null )
01363     {
01364         $this->Host = $sHost;
01365     }
01366 
01372     public function getErrorInfo()
01373     {
01374         return $this->ErrorInfo;
01375     }
01376 
01385     public function setMailWordWrap( $iWordWrap = null )
01386     {
01387         $this->WordWrap = $iWordWrap;
01388     }
01389 
01397     public function setUseInlineImages( $blUseImages = null )
01398     {
01399         $this->_blInlineImgEmail = $blUseImages;
01400     }
01401 
01412     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01413     {
01414         $sFullPath = $sAttPath . $sAttFile;
01415 
01416         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01417         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01418     }
01419 
01431     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01432     {
01433         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01434         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01435     }
01436 
01442     public function getAttachments()
01443     {
01444         return $this->_aAttachments;
01445     }
01446 
01452     public function clearAttachments()
01453     {
01454         $this->_aAttachments = array();
01455         return parent::ClearAttachments();
01456     }
01457 
01467     public function headerLine($sName, $sValue)
01468     {
01469         if (stripos($sName, 'X-') !== false) {
01470             return;
01471         }
01472         return parent::headerLine($sName, $sValue);
01473     }
01474 
01480     protected function _getUseInlineImages()
01481     {
01482         return $this->_blInlineImgEmail;
01483     }
01484 
01490     protected function _sendMailErrorMsg()
01491     {
01492         // build addresses
01493         $sToAdress  = "";
01494         $sToName    = "";
01495 
01496         $aRecipients = $this->getRecipient();
01497 
01498         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01499 
01500         foreach ( $aRecipients as $aEMail ) {
01501             $sOwnerMessage .= $aEMail[0];
01502             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01503             $sOwnerMessage .= " \n ";
01504         }
01505         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01506 
01507         // shop info
01508         $oShop = $this->_getShop();
01509 
01510         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01511 
01512         return $blRet;
01513     }
01514 
01524     protected function _addUserInfoOrderEMail( $oOrder )
01525     {
01526         return $oOrder;
01527     }
01528 
01538     protected function _addUserRegisterEmail( $oUser )
01539     {
01540         return $oUser;
01541     }
01542 
01552     protected function _addForgotPwdEmail( $oShop )
01553     {
01554         return $oShop;
01555     }
01556 
01566     protected function _addNewsletterDbOptInMail( $oUser )
01567     {
01568         return $oUser;
01569     }
01570 
01576     protected function _clearMailer()
01577     {
01578         $this->clearAllRecipients();
01579         $this->clearReplyTos();
01580         $this->clearAttachments();
01581 
01582         //workaround for phpmailer as it doesn't cleanup as it should
01583         $this->error_count = 0;
01584         $this->ErrorInfo   = '';
01585     }
01586 
01594     protected function _setMailParams( $oShop = null )
01595     {
01596         $this->_clearMailer();
01597 
01598         if ( !$oShop ) {
01599             $oShop = $this->_getShop();
01600         }
01601 
01602         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01603         $this->setSmtp( $oShop );
01604     }
01605 
01614     protected function _getShop( $iLangId = null )
01615     {
01616         $myConfig = $this->getConfig();
01617         if ( !isset($iLangId) ) {
01618             $iLangId = 0;
01619             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01620             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01621                 $iLangId = $iActShopLang;
01622             }
01623         }
01624         if ( isset($this->_oShop) && $this->_oShop ) {
01625             // if oShop already setted and reqesting oShop with same language as current oShop,
01626             // or wihtout lang param, return oShop object
01627             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01628                 return $this->_oShop;
01629             }
01630         }
01631 
01632         $this->_oShop = oxNew( 'oxshop' );
01633 
01634         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01635 
01636         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01637 
01638         $oView = $myConfig->getActiveView();
01639         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01640 
01641         return $this->_oShop;
01642     }
01643 
01652     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01653     {
01654         $this->SMTPAuth = true;
01655         $this->Username = $sUserName;
01656         $this->Password = $sUserPassword;
01657     }
01658 
01666     protected function _setSmtpDebug( $blDebug = null )
01667     {
01668         $this->SMTPDebug = $blDebug;
01669     }
01670 
01676     protected function _setMailerPluginDir()
01677     {
01678         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01679     }
01680 
01687     protected function _makeOutputProcessing()
01688     {
01689         $oOutput = oxNew( "oxoutput" );
01690         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01691         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01692         $oOutput->processEmail( $this );
01693     }
01694 
01700     protected function _sendMail()
01701     {
01702         return parent::send();
01703     }
01704 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5