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 {
00015     public $SMTP_PORT = 25;
00016 
00022     protected $_sReminderMailTemplate = "email_owner_reminder_html.tpl";
00023 
00029     protected $_sOrderUserTemplate          = "email_order_cust_html.tpl";
00030 
00036     protected $_sOrderUserPlainTemplate     = "email_order_cust_plain.tpl";
00037 
00043     protected $_sOrderOwnerTemplate         = "email_order_owner_html.tpl";
00044 
00050     protected $_sOrderOwnerPlainTemplate    = "email_order_owner_plain.tpl";
00051 
00052     // #586A - additional templates for more customizable subjects
00053 
00059     protected $_sOrderUserSubjectTemplate   = "email_order_cust_subj.tpl";
00060 
00066     protected $_sOrderOwnerSubjectTemplate  = "email_order_owner_subj.tpl";
00067 
00073     protected $_sOwnerPricealarmTemplate    = "email_pricealarm_owner.tpl";
00074 
00080     protected $_oShop = null;
00081 
00087     protected $_blInlineImgEmail = null;
00088 
00094     protected $_aRecipients = array();
00095 
00101     protected $_aReplies = array();
00102 
00108     protected $_aAttachments = array();
00109 
00113     public function __construct()
00114     {
00115         $myConfig = $this->getConfig();
00116 
00117         $this->_setMailerPluginDir();
00118         $this->setSmtp();
00119 
00120         $this->setUseInlineImages( true );
00121         $this->setMailWordWrap( 100 );
00122 
00123         $this->isHtml( true );
00124         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00125     }
00126 
00138     public function __call( $sMethod, $aArgs )
00139     {
00140         if ( defined( 'OXID_PHP_UNIT' ) ) {
00141             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00142                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00143             }
00144             if ( method_exists( $this, $sMethod)) {
00145                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00146             }
00147         }
00148 
00149         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00150     }
00151 
00157     public function getConfig()
00158     {
00159         if ( $this->_oConfig == null ) {
00160             $this->_oConfig = oxConfig::getInstance();
00161         }
00162 
00163         return $this->_oConfig;
00164     }
00165 
00173     public function setConfig( $oConfig )
00174     {
00175         $this->_oConfig = $oConfig;
00176     }
00177 
00185     public function send()
00186     {
00187         $myConfig = $this->getConfig();
00188         $this->setCharSet();
00189 
00190         if ( $this->_getUseInlineImages() ) {
00191             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00192                                    $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00193         }
00194 
00195         $this->_makeOutputProcessing();
00196 
00197         // try to send mail via SMTP
00198         if ( $this->getMailer() == 'smtp' ) {
00199             $blRet = $this->_sendMail();
00200 
00201             // if sending failed, try to send via mail()
00202             if ( !$blRet ) {
00203                 $this->setMailer( 'mail' );
00204                 $blRet = $this->_sendMail();
00205             }
00206         } else {
00207             // sending mail via mail()
00208             $this->setMailer( 'mail' );
00209             $blRet = $this->_sendMail();
00210         }
00211 
00212         if ( !$blRet ) {
00213             // failed sending, giving up, trying to send notification to shop owner
00214             $this->_sendMailErrorMsg();
00215         }
00216 
00217         return $blRet;
00218     }
00219 
00227     public function setSmtp( $oShop = null )
00228     {
00229         $myConfig = $this->getConfig();
00230         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00231 
00232         if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00233             $this->setMailer( "mail" );
00234             return;
00235         }
00236 
00237         $this->setHost( $oShop->oxshops__oxsmtp->value );
00238         $this->setMailer( "smtp" );
00239 
00240         if ( $oShop->oxshops__oxsmtpuser->value ) {
00241             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00242         }
00243 
00244         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00245             $this->_setSmtpDebug( true );
00246         }
00247     }
00248 
00256     protected function _isValidSmtpHost( $sSmtpHost )
00257     {
00258         $blIsSmtp = false;
00259         if ( $sSmtpHost ) {
00260             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00261                 // closing connection ..
00262                 fclose( $rHandle );
00263             }
00264         }
00265 
00266         return $blIsSmtp;
00267     }
00268 
00277     public function sendOrderEmailToUser( $oOrder )
00278     {
00279         $myConfig = $this->getConfig();
00280 
00281         $sCustHTML  = $this->_sOrderUserTemplate;
00282         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00283 
00284         // add user defined stuff if there is any
00285         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00286 
00287         //set mail params (from, fromName, smtp)
00288         $oShop = $this->_getShop();
00289         $this->_setMailParams( $oShop );
00290 
00291         // P
00292         // setting some deprecated variables
00293         $oOrder->oDelSet = $oOrder->getDelSet();
00294 
00295         // create messages
00296         $smarty = oxUtilsView::getInstance()->getSmarty();
00297         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00298         $smarty->assign( "order", $oOrder);
00299         $smarty->assign( "shop", $oShop );
00300         $smarty->assign( "oViewConf", $oShop );
00301         $smarty->assign( "user", $oOrder->getUser() );
00302         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00303         $smarty->assign( "basket", $oOrder->getBasket() );
00304         $smarty->assign( "payment", $oOrder->getPayment() );
00305         $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00306 
00307         //deprecated vars
00308         $smarty->assign( "iswishlist", true);
00309         $smarty->assign( "isreview", true);
00310 
00311         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00312             $smarty->assign( "vouchers", $aVoucherList );
00313         }
00314 
00315         $oOutputProcessor = oxNew( "oxoutput" );
00316         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00317 
00318         foreach ( $aNewSmartyArray as $key => $val ) {
00319             $smarty->assign( $key, $val );
00320         }
00321 
00322         $this->setBody( $smarty->fetch( $sCustHTML) );
00323         $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00324 
00325         // #586A
00326         if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00327             $this->setSubject( $smarty->fetch( $this->_sOrderUserSubjectTemplate) );
00328         } else {
00329             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00330         }
00331 
00332         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00333 
00334         $this->setRecipient( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00335         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00336 
00337         $blSuccess = $this->send();
00338 
00339         return $blSuccess;
00340     }
00341 
00350     public function sendOrderEmailToOwner( $oOrder )
00351     {
00352         $myConfig = $this->getConfig();
00353 
00354         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00355         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00356 
00357         // cleanup
00358         $this->_clearMailer();
00359 
00360         // add user defined stuff if there is any
00361         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00362 
00363         // send confirmation to shop owner
00364         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00365         $this->setFrom( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00366 
00367         $oLang = oxLang::getInstance();
00368         $iOrderLang = $oLang->getTplLanguage();
00369 
00370         $oShop = $this->_getShop();
00371 
00372         // if running shop language is different from admin lang. set in config
00373         // we have to load shop in config language
00374         if ( $oShop->getLanguage() != $iOrderLang ) {
00375             $oShop = $this->_getShop( $iOrderLang );
00376         }
00377 
00378         $this->setSmtp( $oShop );
00379 
00380         // create messages
00381         $smarty = oxUtilsView::getInstance()->getSmarty();
00382         $smarty->assign( "charset", $oLang->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         //deprecated var
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         //path to admin message template file
00403         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00404 
00405         $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00406         $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00407 
00408         //Sets subject to email
00409         // #586A
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, $oLang->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         // add user history
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         // add user defined stuff if there is any
00448         $oUser = $this->_addUserRegisterEmail( $oUser );
00449 
00450         // shop info
00451         $oShop = $this->_getShop();
00452 
00453         //set mail params (from, fromName, smtp )
00454         $this->_setMailParams( $oShop );
00455 
00456         // create messages
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         // shop info
00496         $oShop = $this->_getShop();
00497 
00498         // add user defined stuff if there is any
00499         $oShop = $this->_addForgotPwdEmail( $oShop);
00500 
00501         //set mail params (from, fromName, smtp)
00502         $this->_setMailParams( $oShop );
00503 
00504         // user
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                 // create messages
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                 //sets subject of email
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         // shop info
00559         $oShop = $this->_getShop();
00560 
00561         //set mail params (from, fromName, smtp)
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         // add user defined stuff if there is any
00586         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00587 
00588         // shop info
00589         $oShop = $this->_getShop();
00590 
00591         //set mail params (from, fromName, smtp)
00592         $this->_setMailParams( $oShop );
00593 
00594         // create messages
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         // shop info
00632         $oShop = $this->_getShop();
00633 
00634         //set mail params (from, fromName, smtp)
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         //sets language of shop
00670         $iCurrLang = 0;
00671         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00672         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00673             $iCurrLang = $iActShopLang;
00674         }
00675 
00676         // shop info
00677         $oShop = $this->_getShop( $iCurrLang );
00678 
00679         //sets language to article
00680         if ( $oProduct->getLanguage() != $iCurrLang ) {
00681             $oProduct->setLanguage( $iCurrLang );
00682             $oProduct->load( $oProduct->getId() );
00683         }
00684 
00685         // mailer stuff
00686         $this->setFrom( $oParams->send_email, $oParams->send_name );
00687         $this->setSMTP();
00688 
00689         // create messages
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         // shop info
00732         $oShop = $this->_getShop( $iOrderLang );
00733 
00734         //set mail params (from, fromName, smtp)
00735         $this->_setMailParams( $oShop );
00736 
00737         //override default wrap
00738         //$this->setMailWordWrap( 0 );
00739 
00740         //create messages
00741         $oLang = oxLang::getInstance();
00742         $smarty = oxUtilsView::getInstance()->getSmarty();
00743         $smarty->assign( "charset", $oLang->translateString("charset"));
00744         $smarty->assign( "shop", $oShop );
00745         $smarty->assign( "oViewConf", $oShop );
00746         $smarty->assign( "order", $oOrder );
00747         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00748 
00749         //deprecated var
00750         $smarty->assign( "isreview", true);
00751 
00752         $oOutputProcessor = oxNew( "oxoutput" );
00753         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00754 
00755         foreach ( $aNewSmartyArray as $key => $val ) {
00756             $smarty->assign( $key, $val );
00757         }
00758 
00759         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00760         $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00761         //V send email in order language
00762         $iOldTplLang = $oLang->getTplLanguage();
00763         $iOldBaseLang = $oLang->getTplLanguage();
00764         $oLang->setTplLanguage( $iOrderLang );
00765         $oLang->setBaseLanguage( $iOrderLang );
00766 
00767         $smarty->security_settings['INCLUDE_ANY'] = true;
00768 
00769         //Sets path to template file
00770         $sPathToTemplate = $myConfig->getTemplateDir(false)."/";
00771 
00772         $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00773         $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00774         $oLang->setTplLanguage( $iOldTplLang );
00775         $oLang->setBaseLanguage( $iOldBaseLang );
00776         // set it back
00777         $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00778 
00779         //Sets subject to email
00780         $this->setSubject( $oShop->oxshops__oxsendednowsubject->value );
00781 
00782         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00783 
00784         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00785         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00786         return $this->send();
00787     }
00788 
00803     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00804     {
00805 
00806         /* P
00807         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00808         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00809         */
00810 
00811         // shop info
00812         $oShop = $this->_getShop();
00813 
00814         //set mail params (from, fromName, smtp)
00815         $this->_setMailParams( $oShop );
00816 
00817         $this->setBody( $sMessage );
00818         $this->setSubject( $sSubject );
00819 
00820         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00821 
00822         if ( !$sEmailAddress ) {
00823             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00824         }
00825 
00826         $this->setFrom( $sEmailAddress, "" );
00827         $this->setReplyTo( $sEmailAddress, "" );
00828 
00829         //attaching files
00830         $blAttashSucc = true;
00831         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00832         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00833             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00834                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00835             } else {
00836                 $blAttashSucc = false;
00837                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00838             }
00839         }
00840 
00841         if ( !$blAttashSucc ) {
00842             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00843             $this->clearAttachments();
00844             return false;
00845         }
00846 
00847         $aStatus[] = 3;     //"Mailing backup files ...";
00848         $blSend = $this->send();
00849         $this->clearAttachments();
00850 
00851         return $blSend;
00852     }
00853 
00864     public function sendEmail( $sTo, $sSubject, $sBody )
00865     {
00866         //set mail params (from, fromName, smtp)
00867         $this->_setMailParams();
00868 
00869         if ( is_array($sTo) ) {
00870             foreach ($sTo as $sAddress) {
00871                 $this->setRecipient( $sAddress, "" );
00872                 $this->setReplyTo( $sAddress, "" );
00873             }
00874         } else {
00875             $this->setRecipient( $sTo, "" );
00876             $this->setReplyTo( $sTo, "" );
00877         }
00878 
00879         //may be changed later
00880         $this->isHtml( false );
00881 
00882         $this->setSubject( $sSubject );
00883         $this->setBody( $sBody );
00884 
00885         return $this->send();
00886     }
00887 
00895     public function sendStockReminder( $aBasketContents )
00896     {
00897         $myConfig = $this->getConfig();
00898 
00899         $aRemindArticles = array();
00900         foreach ( $aBasketContents as $oBasketItem ) {
00901             $oArticle = $oBasketItem->getArticle();
00902              // reminder not set
00903             if ( !$oArticle->oxarticles__oxremindactive->value || $oArticle->oxarticles__oxremindactive->value > 1 ) {
00904                 continue;
00905             }
00906 
00907             // number or articles available is more
00908             if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00909                 continue;
00910             }
00911 
00912             $aRemindArticles[] = $oArticle;
00913             $oArticle->disableReminder();
00914         }
00915 
00916         // nothing to remind ...
00917         if ( !count( $aRemindArticles ) ) {
00918             return false;
00919         }
00920         $oShop = $this->_getShop();
00921 
00922         //set mail params (from, fromName, smtp... )
00923         $this->_setMailParams( $oShop );
00924         $oLang = oxLang::getInstance();
00925 
00926 
00927         $smarty = oxUtilsView::getInstance()->getSmarty();
00928         $smarty->assign( "charset", $oLang->translateString("charset"));
00929         $smarty->assign( "shop", $oShop );
00930         $smarty->assign( "oViewConf", $oShop );
00931         $smarty->assign( "articles", $aRemindArticles );
00932 
00933         //path to admin message template file
00934         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00935 
00936         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00937         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00938         $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00939         $this->setAltBody( "" );
00940         $this->setSubject( $oLang->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00941 
00942         return $this->send();
00943     }
00944 
00953     public function sendWishlistMail( $oParams )
00954     {
00955         $myConfig = $this->getConfig();
00956 
00957         $this->_clearMailer();
00958 
00959         // shop info
00960         $oShop = $this->_getShop();
00961 
00962         // mailer stuff
00963         $this->setFrom( $oParams->send_email, $oParams->send_name );
00964         $this->setSMTP();
00965 
00966         // create messages
00967         $smarty = oxUtilsView::getInstance()->getSmarty();
00968         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00969         $smarty->assign( "shop", $oShop );
00970         $smarty->assign( "oViewConf", $oShop );
00971         $smarty->assign( "userinfo", $oParams );
00972 
00973         $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
00974         $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
00975         $this->setSubject( $oParams->send_subject );
00976 
00977         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00978         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00979 
00980         return $this->send();
00981     }
00982 
00992     public function sendPriceAlarmNotification( $aParams, $oAlarm )
00993     {
00994         $this->_clearMailer();
00995         $oShop = $this->_getShop();
00996 
00997         //set mail params (from, fromName, smtp)
00998         $this->_setMailParams( $oShop );
00999 
01000         $iAlarmLang = $oShop->getLanguage();
01001 
01002         $oArticle = oxNew( "oxarticle" );
01003         $oArticle->setSkipAbPrice( true );
01004         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01005 
01006         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01007         $oLang = oxLang::getInstance();
01008 
01009         // create messages
01010         $smarty = oxUtilsView::getInstance()->getSmarty();
01011         $smarty->assign( "shop", $oShop );
01012         $smarty->assign( "oViewConf", $oShop );
01013         $smarty->assign( "product", $oArticle );
01014         $smarty->assign( "email", $aParams['email']);
01015         $smarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01016         $smarty->assign( "currency", $oCur );
01017 
01018         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01019         $sSubject = $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value;
01020         $this->setSubject( $sSubject );
01021         $this->setBody( $smarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01022         $this->setFrom( $aParams['email'], "" );
01023         $this->setReplyTo( $aParams['email'], "" );
01024 
01025         return $this->send();
01026     }
01027 
01039     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01040     {
01041         $sBody = $this->getBody();
01042         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01043 
01044             $oFileUtils = oxUtilsFile::getInstance();
01045             $blReSetBody = false;
01046 
01047             // preparing imput
01048             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01049             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01050             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01051 
01052             if (is_array($matches) && count($matches)) {
01053                 $aImageCache = array();
01054                 $myUtils = oxUtils::getInstance();
01055                 $myUtilsObject = oxUtilsObject::getInstance();
01056 
01057                 foreach ($matches as $aImage) {
01058 
01059                     $image = $aImage[1];
01060                     $sFileName = '';
01061                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01062                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01063                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01064                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01065                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01066                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01067                     }
01068 
01069                     if ($sFileName && @is_file($sFileName)) {
01070                         $sCId = '';
01071                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01072                             $sCId = $aImageCache[$sFileName];
01073                         } else {
01074                             $sCId = $myUtilsObject->generateUID();
01075                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01076                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01077                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01078                                     $aImageCache[$sFileName] = $sCId;
01079                                 } else {
01080                                     $sCId = '';
01081                                 }
01082                             }
01083                         }
01084                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01085                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01086                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01087                                 $blReSetBody = true;
01088                             }
01089                         }
01090                     }
01091                 }
01092             }
01093 
01094             if ( $blReSetBody ) {
01095                 $this->setBody( $sBody );
01096             }
01097         }
01098     }
01099 
01107     public function setSubject( $sSubject = null )
01108     {
01109         // A. HTML entites in subjects must be replaced
01110         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01111         $this->Subject = $sSubject;
01112     }
01113 
01119     public function getSubject()
01120     {
01121         return $this->Subject;
01122     }
01123 
01133     public function setBody( $sBody = null, $blClearSid = true )
01134     {
01135         if ( $blClearSid ) {
01136             $sBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01137         }
01138 
01139         $this->Body = $sBody;
01140     }
01141 
01147     public function getBody()
01148     {
01149         return $this->Body;
01150     }
01151 
01161     public function setAltBody( $sAltBody = null, $blClearSid = true )
01162     {
01163         if ( $blClearSid ) {
01164             $sAltBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01165         }
01166 
01167         // A. alt body is used for plain text emails so we should eliminate HTML entities
01168         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01169         $this->AltBody = $sAltBody;
01170     }
01171 
01177     public function getAltBody()
01178     {
01179         return $this->AltBody;
01180     }
01181 
01190     public function setRecipient( $sAddress = null, $sName = null )
01191     {
01192         // copying values as original class does not allow to access recipients array
01193         $this->_aRecipients[] = array( $sAddress, $sName );
01194 
01195         parent::AddAddress($sAddress, $sName );
01196     }
01197 
01205     public function getRecipient()
01206     {
01207         return $this->_aRecipients;
01208     }
01209 
01216     public function clearAllRecipients()
01217     {
01218         $this->_aRecipients = array();
01219         parent::clearAllRecipients();
01220     }
01221 
01233     public function setReplyTo( $sEmail = null, $sName = null )
01234     {
01235         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01236             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01237         }
01238 
01239         $this->_aReplies[] = array( $sEmail, $sName );
01240         parent::AddReplyTo( $sEmail, $sName );
01241     }
01242 
01248     public function getReplyTo()
01249     {
01250         return $this->_aReplies;
01251     }
01252 
01258     public function clearReplyTos()
01259     {
01260         $this->_aReplies = array();
01261         parent::clearReplyTos();
01262     }
01263 
01272     public function setFrom( $sFromAdress = null, $sFromName = null )
01273     {
01274         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01275         // this is simple but must work
01276         // dodger Task #1532 field "From" in emails from shops
01277         $this->From     = substr($sFromAdress, 0, 150);
01278         $this->FromName = substr($sFromName, 0, 150);
01279     }
01280 
01286     public function getFrom()
01287     {
01288         return $this->From;
01289     }
01290 
01296     public function getFromName()
01297     {
01298         return $this->FromName;
01299     }
01300 
01309     public function setCharSet( $sCharSet = null )
01310     {
01311         if ( !empty($sCharSet) ) {
01312             $this->CharSet = $sCharSet;
01313         } else {
01314             $this->CharSet = oxLang::getInstance()->translateString("charset");
01315         }
01316     }
01317 
01323     public function getCharSet()
01324     {
01325         return $this->CharSet;
01326     }
01327 
01335     public function setMailer( $sMailer = null )
01336     {
01337         $this->Mailer = $sMailer;
01338     }
01339 
01345     public function getMailer()
01346     {
01347         return $this->Mailer;
01348     }
01349 
01357     public function setHost( $sHost = null )
01358     {
01359         $this->Host = $sHost;
01360     }
01361 
01367     public function getErrorInfo()
01368     {
01369         return $this->ErrorInfo;
01370     }
01371 
01380     public function setMailWordWrap( $iWordWrap = null )
01381     {
01382         $this->WordWrap = $iWordWrap;
01383     }
01384 
01392     public function setUseInlineImages( $blUseImages = null )
01393     {
01394         $this->_blInlineImgEmail = $blUseImages;
01395     }
01396 
01407     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01408     {
01409         $sFullPath = $sAttPath . $sAttFile;
01410 
01411         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01412         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01413     }
01414 
01426     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01427     {
01428         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01429         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01430     }
01431 
01437     public function getAttachments()
01438     {
01439         return $this->_aAttachments;
01440     }
01441 
01447     public function clearAttachments()
01448     {
01449         $this->_aAttachments = array();
01450         return parent::ClearAttachments();
01451     }
01452 
01462     public function headerLine($sName, $sValue)
01463     {
01464         if (stripos($sName, 'X-') !== false) {
01465             return;
01466         }
01467         return parent::headerLine($sName, $sValue);
01468     }
01469 
01475     protected function _getUseInlineImages()
01476     {
01477         return $this->_blInlineImgEmail;
01478     }
01479 
01485     protected function _sendMailErrorMsg()
01486     {
01487         // build addresses
01488         $sToAdress  = "";
01489         $sToName    = "";
01490 
01491         $aRecipients = $this->getRecipient();
01492 
01493         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01494 
01495         foreach ( $aRecipients as $aEMail ) {
01496             $sOwnerMessage .= $aEMail[0];
01497             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01498             $sOwnerMessage .= " \n ";
01499         }
01500         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01501 
01502         // shop info
01503         $oShop = $this->_getShop();
01504 
01505         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01506 
01507         return $blRet;
01508     }
01509 
01519     protected function _addUserInfoOrderEMail( $oOrder )
01520     {
01521         return $oOrder;
01522     }
01523 
01533     protected function _addUserRegisterEmail( $oUser )
01534     {
01535         return $oUser;
01536     }
01537 
01547     protected function _addForgotPwdEmail( $oShop )
01548     {
01549         return $oShop;
01550     }
01551 
01561     protected function _addNewsletterDbOptInMail( $oUser )
01562     {
01563         return $oUser;
01564     }
01565 
01571     protected function _clearMailer()
01572     {
01573         $this->clearAllRecipients();
01574         $this->clearReplyTos();
01575         $this->clearAttachments();
01576 
01577         //workaround for phpmailer as it doesn't cleanup as it should
01578         $this->error_count = 0;
01579         $this->ErrorInfo   = '';
01580     }
01581 
01589     protected function _setMailParams( $oShop = null )
01590     {
01591         $this->_clearMailer();
01592 
01593         if ( !$oShop ) {
01594             $oShop = $this->_getShop();
01595         }
01596 
01597         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01598         $this->setSmtp( $oShop );
01599     }
01600 
01609     protected function _getShop( $iLangId = null )
01610     {
01611         $myConfig = $this->getConfig();
01612         if ( !isset($iLangId) ) {
01613             $iLangId = 0;
01614             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01615             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01616                 $iLangId = $iActShopLang;
01617             }
01618         }
01619         if ( isset($this->_oShop) && $this->_oShop ) {
01620             // if oShop already setted and reqesting oShop with same language as current oShop,
01621             // or wihtout lang param, return oShop object
01622             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01623                 return $this->_oShop;
01624             }
01625         }
01626 
01627         $this->_oShop = oxNew( 'oxshop' );
01628 
01629         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01630 
01631         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01632 
01633         $oView = $myConfig->getActiveView();
01634         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01635 
01636         return $this->_oShop;
01637     }
01638 
01647     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01648     {
01649         $this->SMTPAuth = true;
01650         $this->Username = $sUserName;
01651         $this->Password = $sUserPassword;
01652     }
01653 
01661     protected function _setSmtpDebug( $blDebug = null )
01662     {
01663         $this->SMTPDebug = $blDebug;
01664     }
01665 
01671     protected function _setMailerPluginDir()
01672     {
01673         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01674     }
01675 
01682     protected function _makeOutputProcessing()
01683     {
01684         $oOutput = oxNew( "oxoutput" );
01685         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01686         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01687         $oOutput->processEmail( $this );
01688     }
01689 
01695     protected function _sendMail()
01696     {
01697         return parent::send();
01698     }
01699 }

Generated on Tue Apr 21 15:45:44 2009 for OXID eShop CE by  doxygen 1.5.5