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 $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
00028 
00034     protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
00035 
00041     protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
00042 
00048     protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
00049 
00055     protected $_sSuggestTemplate = "email/html/suggest.tpl";
00056 
00062     protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
00063 
00069     protected $_sInviteTemplate = "email/html/invite.tpl";
00070 
00076     protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
00077 
00083     protected $_sSenedNowTemplate = "email/html/sendednow.tpl";
00084 
00090     protected $_sSenedNowTemplatePlain = "email/plain/sendednow.tpl";
00091 
00097     protected $_sWishListTemplate = "email/html/wishlist.tpl";
00098 
00104     protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00105 
00111     protected $_sRegisterTemplate = "email/html/register.tpl";
00112 
00118     protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00119 
00125     protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00126 
00132     protected $_sOrderUserTemplate          = "email/html/order_cust.tpl";
00133 
00139     protected $_sOrderUserPlainTemplate     = "email/plain/order_cust.tpl";
00140 
00146     protected $_sOrderOwnerTemplate         = "email/html/order_owner.tpl";
00147 
00153     protected $_sOrderOwnerPlainTemplate    = "email/plain/order_owner.tpl";
00154 
00155     // #586A - additional templates for more customizable subjects
00156 
00162     protected $_sOrderUserSubjectTemplate   = "email/html/order_cust_subj.tpl";
00163 
00169     protected $_sOrderOwnerSubjectTemplate  = "email/html/order_owner_subj.tpl";
00170 
00176     protected $_sOwnerPricealarmTemplate    = "email/html/pricealarm_owner.tpl";
00177 
00183     protected $_sPricealamrCustomerTemplate    = "email_pricealarm_customer.tpl";
00184 
00190     protected $_aShops = array();
00191 
00197     protected $_blInlineImgEmail = null;
00198 
00204     protected $_aRecipients = array();
00205 
00211     protected $_aReplies = array();
00212 
00218     protected $_aAttachments = array();
00219 
00225     protected $_oSmarty = null;
00226 
00232     protected $_aViewData = array();
00233 
00239     protected $_oShop = null;
00240 
00246     protected $_sCharSet = null;
00247 
00251     public function __construct()
00252     {
00253         //enabling exception handling in phpmailer class
00254         parent::__construct( true );
00255 
00256         $myConfig = $this->getConfig();
00257 
00258         $this->_setMailerPluginDir();
00259         $this->setSmtp();
00260 
00261         $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00262         $this->setMailWordWrap( 100 );
00263 
00264         $this->isHtml( true );
00265         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00266 
00267         $this->_getSmarty();
00268     }
00269 
00281     public function __call( $sMethod, $aArgs )
00282     {
00283         if ( defined( 'OXID_PHP_UNIT' ) ) {
00284             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00285                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00286             }
00287             if ( method_exists( $this, $sMethod)) {
00288                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00289             }
00290         }
00291 
00292         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00293     }
00294 
00300     public function getConfig()
00301     {
00302         if ( $this->_oConfig == null ) {
00303             $this->_oConfig = oxConfig::getInstance();
00304         }
00305 
00306         return $this->_oConfig;
00307     }
00308 
00316     public function setConfig( $oConfig )
00317     {
00318         $this->_oConfig = $oConfig;
00319     }
00320 
00321 
00327     protected function _getSmarty()
00328     {
00329         if ( $this->_oSmarty === null ) {
00330             $this->_oSmarty = oxUtilsView::getInstance()->getSmarty();
00331         }
00332 
00333         //setting default view
00334         $this->_oSmarty->assign( "oEmailView", $this );
00335 
00336         return $this->_oSmarty;
00337     }
00338 
00346     public function send()
00347     {
00348         // if no recipients found, skipping sending
00349         if ( count( $this->getRecipient() ) < 1 ) {
00350             return false;
00351         }
00352 
00353         $myConfig = $this->getConfig();
00354         $this->setCharSet();
00355 
00356         if ( $this->_getUseInlineImages() ) {
00357             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( isAdmin() ), $myConfig->getPictureUrl(null, false),
00358                                    $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00359         }
00360 
00361         $this->_makeOutputProcessing();
00362 
00363         // try to send mail via SMTP
00364         if ( $this->getMailer() == 'smtp' ) {
00365             $blRet = $this->_sendMail();
00366 
00367             // if sending failed, try to send via mail()
00368             if ( !$blRet ) {
00369                 // failed sending via SMTP, sending notification to shop owner
00370                 $this->_sendMailErrorMsg();
00371 
00372                 // trying to send using standard mailer
00373                 $this->setMailer( 'mail' );
00374                 $blRet = $this->_sendMail();
00375             }
00376         } else {
00377             // sending mail via mail()
00378             $this->setMailer( 'mail' );
00379             $blRet = $this->_sendMail();
00380         }
00381 
00382         if ( !$blRet ) {
00383             // failed sending, giving up, trying to send notification to shop owner
00384             $this->_sendMailErrorMsg();
00385         }
00386 
00387         return $blRet;
00388     }
00389 
00398     protected function _setSmtpProtocol($sUrl)
00399     {
00400         $sProtocol = '';
00401         $sSmtpHost = $sUrl;
00402         $aMatch = array();
00403         if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00404             if ($aMatch[1]) {
00405                 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00406                     $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00407                 } else {
00408                     $sProtocol = $aMatch[1];
00409                 }
00410             }
00411             $sSmtpHost = $aMatch[2];
00412         }
00413 
00414         return $sProtocol.$sSmtpHost;
00415     }
00416 
00424     public function setSmtp( $oShop = null )
00425     {
00426         $myConfig = $this->getConfig();
00427         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00428 
00429         $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00430 
00431         if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00432             $this->setMailer( "mail" );
00433             return;
00434         }
00435 
00436         $this->setHost( $sSmtpUrl );
00437         $this->setMailer( "smtp" );
00438 
00439         if ( $oShop->oxshops__oxsmtpuser->value ) {
00440             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00441         }
00442 
00443         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00444             $this->_setSmtpDebug( true );
00445         }
00446     }
00447 
00455     protected function _isValidSmtpHost( $sSmtpHost )
00456     {
00457         $blIsSmtp = false;
00458         if ( $sSmtpHost ) {
00459             $sSmtpPort = $this->SMTP_PORT;
00460             $aMatch = array();
00461             if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00462                 $sSmtpHost = $aMatch[1];
00463                 $sSmtpPort = (int)$aMatch[3];
00464                 if (!$sSmtpPort) {
00465                     $sSmtpPort = $this->SMTP_PORT;
00466                 }
00467             }
00468             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00469                 // closing connection ..
00470                 fclose( $rHandle );
00471             }
00472         }
00473 
00474         return $blIsSmtp;
00475     }
00476 
00486     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00487     {
00488         $myConfig = $this->getConfig();
00489 
00490         // add user defined stuff if there is any
00491         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00492 
00493         $oShop = $this->_getShop();
00494         $this->_setMailParams( $oShop );
00495 
00496         $oUser = $oOrder->getOrderUser();
00497         $this->setUser( $oUser );
00498 
00499         // create messages
00500         $oSmarty = $this->_getSmarty();
00501         $this->setViewData( "order", $oOrder);
00502 
00503         // Process view data array through oxoutput processor
00504         $this->_processViewArray();
00505 
00506         $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00507         $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00508 
00509         // #586A
00510         if ( $sSubject === null ) {
00511             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00512                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00513             } else {
00514                 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00515             }
00516         }
00517 
00518         $this->setSubject( $sSubject );
00519 
00520         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00521 
00522         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00523         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00524 
00525         $blSuccess = $this->send();
00526 
00527         return $blSuccess;
00528     }
00529 
00539     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00540     {
00541         $myConfig = $this->getConfig();
00542 
00543         $oShop = $this->_getShop();
00544 
00545         // cleanup
00546         $this->_clearMailer();
00547 
00548         // add user defined stuff if there is any
00549         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00550 
00551         $oUser = $oOrder->getOrderUser();
00552         $this->setUser( $oUser );
00553 
00554         // send confirmation to shop owner
00555         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00556         $this->setFrom( $oUser->oxuser__oxusername->value, $sFullName );
00557 
00558         $oLang = oxLang::getInstance();
00559         $iOrderLang = $oLang->getObjectTplLanguage();
00560 
00561         // if running shop language is different from admin lang. set in config
00562         // we have to load shop in config language
00563         if ( $oShop->getLanguage() != $iOrderLang ) {
00564             $oShop = $this->_getShop( $iOrderLang );
00565         }
00566 
00567         $this->setSmtp( $oShop );
00568 
00569         // create messages
00570         $oSmarty = $this->_getSmarty();
00571         $this->setViewData( "order", $oOrder );
00572 
00573         // Process view data array through oxoutput processor
00574         $this->_processViewArray();
00575 
00576         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00577         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00578 
00579         //Sets subject to email
00580         // #586A
00581         if ( $sSubject === null ) {
00582             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00583                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00584             } else {
00585                  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00586             }
00587         }
00588 
00589         $this->setSubject( $sSubject );
00590         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00591 
00592         if ( $oUser->oxuser__oxusername->value != "admin" )
00593             $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00594 
00595         $blSuccess = $this->send();
00596 
00597         // add user history
00598         $oRemark = oxNew( "oxremark" );
00599         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00600         $oRemark->oxremark__oxparentid  = new oxField($oUser->getId(), oxField::T_RAW);
00601         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00602         $oRemark->save();
00603 
00604 
00605         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00606             oxUtils::getInstance()->showMessageAndExit( "" );
00607         }
00608 
00609         return $blSuccess;
00610     }
00611 
00621     public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00622     {
00623         // setting content ident
00624 
00625         $this->setViewData( "contentident", "oxregisteraltemail" );
00626         $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00627 
00628         // sending email
00629         return $this->sendRegisterEmail( $oUser, $sSubject );
00630     }
00631 
00641     public function sendRegisterEmail( $oUser, $sSubject = null )
00642     {
00643         // add user defined stuff if there is any
00644         $oUser = $this->_addUserRegisterEmail( $oUser );
00645 
00646         // shop info
00647         $oShop = $this->_getShop();
00648 
00649         //set mail params (from, fromName, smtp )
00650         $this->_setMailParams( $oShop );
00651 
00652         // create messages
00653         $oSmarty = $this->_getSmarty();
00654         $this->setUser( $oUser );
00655 
00656         // Process view data array through oxoutput processor
00657         $this->_processViewArray();
00658 
00659         $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00660         $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00661 
00662         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00663 
00664         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00665 
00666         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00667         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00668 
00669         return $this->send();
00670     }
00671 
00681     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00682     {
00683         $myConfig = $this->getConfig();
00684         $oDb = oxDb::getDb();
00685 
00686         // shop info
00687         $oShop = $this->_getShop();
00688 
00689         // add user defined stuff if there is any
00690         $oShop = $this->_addForgotPwdEmail( $oShop );
00691 
00692         //set mail params (from, fromName, smtp)
00693         $this->_setMailParams( $oShop );
00694 
00695         // user
00696         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00697         $sOrder = "";
00698         if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00699             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00700         } else {
00701             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00702         }
00703 
00704         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00705         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00706 
00707             $oUser = oxNew( 'oxuser' );
00708             if ( $oUser->load($sOxId) ) {
00709                 // create messages
00710                 $oSmarty = $this->_getSmarty();
00711                 $this->setUser( $oUser );
00712 
00713                 // Process view data array through oxoutput processor
00714                 $this->_processViewArray();
00715 
00716                 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00717 
00718                 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00719 
00720                 //sets subject of email
00721                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00722 
00723                 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00724 
00725                 $this->setRecipient( $sEmailAddress, $sFullName );
00726                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00727 
00728                 return $this->send();
00729             }
00730         }
00731 
00732         return false;
00733     }
00734 
00745     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00746     {
00747 
00748         // shop info
00749         $oShop = $this->_getShop();
00750 
00751         //set mail params (from, fromName, smtp)
00752         $this->_setMailParams( $oShop );
00753 
00754         $this->setBody( $sMessage );
00755         $this->setSubject( $sSubject );
00756 
00757         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00758         $this->setFrom( $sEmailAddress, "" );
00759         $this->setReplyTo( $sEmailAddress, "" );
00760 
00761         return $this->send();
00762     }
00763 
00773     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00774     {
00775         $oLang = oxLang::getInstance();
00776 
00777         // add user defined stuff if there is any
00778         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00779 
00780         // shop info
00781         $oShop = $this->_getShop();
00782 
00783         //set mail params (from, fromName, smtp)
00784         $this->_setMailParams( $oShop );
00785 
00786         // create messages
00787         $oSmarty = $this->_getSmarty();
00788         $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value) );
00789         $this->setUser( $oUser );
00790 
00791         // Process view data array through oxoutput processor
00792         $this->_processViewArray();
00793 
00794         $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00795         $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00796         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00797 
00798         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00799 
00800         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00801         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00802         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00803 
00804         return $this->send();
00805     }
00806 
00814     protected function _getNewsSubsLink( $sId )
00815     {
00816         $myConfig = $this->getConfig();
00817         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00818 
00819         $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
00820         $sUrl.= ( $iActShopLang ) ? '&amp;lang='.$iActShopLang : "";
00821         return $sUrl;
00822     }
00823 
00834     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00835     {
00836         // shop info
00837         $oShop = $this->_getShop();
00838 
00839         //set mail params (from, fromName, smtp)
00840         $this->_setMailParams( $oShop );
00841 
00842         $sBody = $oNewsLetter->getHtmlText();
00843 
00844         if ( !empty($sBody) ) {
00845             $this->setBody( $sBody );
00846             $this->setAltBody( $oNewsLetter->getPlainText() );
00847         } else {
00848             $this->isHtml( false );
00849             $this->setBody( $oNewsLetter->getPlainText() );
00850         }
00851 
00852         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00853 
00854         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00855         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00856         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00857 
00858         return $this->send();
00859     }
00860 
00870     public function sendSuggestMail( $oParams, $oProduct )
00871     {
00872         $myConfig = $this->getConfig();
00873 
00874         //sets language of shop
00875         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00876 
00877         // shop info
00878         $oShop = $this->_getShop( $iCurrLang );
00879 
00880         //sets language to article
00881         if ( $oProduct->getLanguage() != $iCurrLang ) {
00882             $oProduct->setLanguage( $iCurrLang );
00883             $oProduct->load( $oProduct->getId() );
00884         }
00885 
00886         // mailer stuff
00887         $this->setFrom( $oParams->send_email, $oParams->send_name );
00888         $this->setSMTP();
00889 
00890         // create messages
00891         $oSmarty = $this->_getSmarty();
00892         $this->setViewData( "product", $oProduct );
00893         $this->setUser( $oParams );
00894 
00895         $sArticleUrl = $oProduct->getLink();
00896 
00897         //setting recommended user id
00898         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00899             $sArticleUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sArticleUrl );
00900             $sArticleUrl .= "su=" . $oActiveUser->getId();
00901         }
00902 
00903         $this->setViewData( "sArticleUrl", $sArticleUrl );
00904 
00905         // Process view data array through oxoutput processor
00906         $this->_processViewArray();
00907 
00908         $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00909         $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00910         $this->setSubject( $oParams->send_subject );
00911 
00912         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00913         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00914 
00915         return $this->send();
00916     }
00917 
00926     public function sendInviteMail( $oParams )
00927     {
00928         $myConfig = $this->getConfig();
00929 
00930         //sets language of shop
00931         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00932 
00933         // shop info
00934         $oShop = $this->_getShop( $iCurrLang );
00935 
00936         // mailer stuff
00937         $this->setFrom( $oParams->send_email, $oParams->send_name );
00938         $this->setSMTP();
00939 
00940         // create messages
00941         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00942         $this->setUser( $oParams );
00943 
00944         $sHomeUrl = $this->getViewConfig()->getHomeLink();
00945 
00946         //setting recommended user id
00947         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00948             $sHomeUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00949             $sHomeUrl .= "su=" . $oActiveUser->getId();
00950         }
00951 
00952         $this->setViewData( "sHomeUrl", $sHomeUrl );
00953 
00954         // Process view data array through oxoutput processor
00955         $this->_processViewArray();
00956 
00957         $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00958 
00959         $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00960         $this->setSubject( $oParams->send_subject );
00961 
00962         if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0  ) {
00963             foreach ( $oParams->rec_email as $sEmail ) {
00964                 if ( !empty( $sEmail ) ) {
00965                     $this->setRecipient( $sEmail );
00966                     $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00967                     $this->send();
00968                     $this->clearAllRecipients();
00969                 }
00970             }
00971 
00972             return true;
00973         }
00974 
00975         return false;
00976     }
00977 
00987     public function sendSendedNowMail( $oOrder, $sSubject = null )
00988     {
00989         $myConfig = $this->getConfig();
00990 
00991         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
00992 
00993         // shop info
00994         $oShop = $this->_getShop( $iOrderLang );
00995 
00996         //set mail params (from, fromName, smtp)
00997         $this->_setMailParams( $oShop );
00998 
00999         //create messages
01000         $oLang = oxLang::getInstance();
01001         $oSmarty = $this->_getSmarty();
01002         $this->setViewData( "order", $oOrder );
01003 
01004         //deprecated var
01005         $oUser = oxNew( 'oxuser' );
01006         $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01007 
01008         // Process view data array through oxoutput processor
01009         $this->_processViewArray();
01010 
01011         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01012         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01013         //V send email in order language
01014         $iOldTplLang = $oLang->getTplLanguage();
01015         $iOldBaseLang = $oLang->getTplLanguage();
01016         $oLang->setTplLanguage( $iOrderLang );
01017         $oLang->setBaseLanguage( $iOrderLang );
01018 
01019         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01020 
01021         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sSenedNowTemplate, false ) ) );
01022         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sSenedNowTemplatePlain, false ) ) );
01023         $oLang->setTplLanguage( $iOldTplLang );
01024         $oLang->setBaseLanguage( $iOldBaseLang );
01025         // set it back
01026         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01027 
01028         //Sets subject to email
01029         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01030 
01031         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01032 
01033         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01034         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01035 
01036         return $this->send();
01037     }
01038 
01053     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01054     {
01055         // shop info
01056         $oShop = $this->_getShop();
01057 
01058         //set mail params (from, fromName, smtp)
01059         $this->_setMailParams( $oShop );
01060 
01061         $this->setBody( $sMessage );
01062         $this->setSubject( $sSubject );
01063 
01064         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01065         $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01066 
01067         $this->setFrom( $sEmailAddress, "" );
01068         $this->setReplyTo( $sEmailAddress, "" );
01069 
01070         //attaching files
01071         $blAttashSucc = true;
01072         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
01073         foreach ( $aAttFiles as $iNum => $sAttFile ) {
01074             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
01075                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
01076             } else {
01077                 $blAttashSucc = false;
01078                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
01079             }
01080         }
01081 
01082         if ( !$blAttashSucc ) {
01083             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
01084             $this->clearAttachments();
01085             return false;
01086         }
01087 
01088         $aStatus[] = 3;     //"Mailing backup files ...";
01089         $blSend = $this->send();
01090         $this->clearAttachments();
01091 
01092         return $blSend;
01093     }
01094 
01105     public function sendEmail( $sTo, $sSubject, $sBody )
01106     {
01107         //set mail params (from, fromName, smtp)
01108         $this->_setMailParams();
01109 
01110         if ( is_array($sTo) ) {
01111             foreach ($sTo as $sAddress) {
01112                 $this->setRecipient( $sAddress, "" );
01113                 $this->setReplyTo( $sAddress, "" );
01114             }
01115         } else {
01116             $this->setRecipient( $sTo, "" );
01117             $this->setReplyTo( $sTo, "" );
01118         }
01119 
01120         //may be changed later
01121         $this->isHtml( false );
01122 
01123         $this->setSubject( $sSubject );
01124         $this->setBody( $sBody );
01125 
01126         return $this->send();
01127     }
01128 
01137     public function sendStockReminder( $aBasketContents, $sSubject = null )
01138     {
01139         $blSend = false;
01140 
01141         $oArticleList = oxNew( "oxarticlelist" );
01142         $oArticleList->loadStockRemindProducts( $aBasketContents );
01143 
01144         // nothing to remind?
01145         if ( $oArticleList->count() ) {
01146             $oShop = $this->_getShop();
01147 
01148             //set mail params (from, fromName, smtp... )
01149             $this->_setMailParams( $oShop );
01150             $oLang = oxLang::getInstance();
01151 
01152             $oSmarty = $this->_getSmarty();
01153             $this->setViewData( "articles", $oArticleList );
01154 
01155             // Process view data array through oxoutput processor
01156             $this->_processViewArray();
01157 
01158             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01159             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01160             $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01161             $this->setAltBody( "" );
01162             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01163 
01164             $blSend = $this->send();
01165         }
01166 
01167         return $blSend;
01168     }
01169 
01178     public function sendWishlistMail( $oParams )
01179     {
01180         $myConfig = $this->getConfig();
01181 
01182         $this->_clearMailer();
01183 
01184         // shop info
01185         $oShop = $this->_getShop();
01186 
01187         // mailer stuff
01188         $this->setFrom( $oParams->send_email, $oParams->send_name );
01189         $this->setSMTP();
01190 
01191         // create messages
01192         $oSmarty = $this->_getSmarty();
01193         $this->setUser( $oParams );
01194 
01195         // Process view data array through oxoutput processor
01196         $this->_processViewArray();
01197 
01198         $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01199         $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01200         $this->setSubject( $oParams->send_subject );
01201 
01202         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01203         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01204 
01205         return $this->send();
01206     }
01207 
01218     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01219     {
01220         $this->_clearMailer();
01221         $oShop = $this->_getShop();
01222 
01223         //set mail params (from, fromName, smtp)
01224         $this->_setMailParams( $oShop );
01225 
01226         $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01227 
01228         $oArticle = oxNew( "oxarticle" );
01229         $oArticle->setSkipAbPrice( true );
01230         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01231 
01232         $oLang = oxLang::getInstance();
01233 
01234         // create messages
01235         $oSmarty = $this->_getSmarty();
01236         $this->setViewData( "product", $oArticle );
01237         $this->setViewData( "email", $aParams['email']);
01238         $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01239 
01240         // Process view data array through oxoutput processor
01241         $this->_processViewArray();
01242 
01243         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01244         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01245         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01246         $this->setFrom( $aParams['email'], "" );
01247         $this->setReplyTo( $aParams['email'], "" );
01248 
01249         return $this->send();
01250     }
01251 
01263     public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01264     {
01265         $this->_clearMailer();
01266 
01267         $oShop = $this->_getShop();
01268 
01269         if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01270             $oShop = oxNew( "oxshop" );
01271             $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01272             $this->setShop( $oShop );
01273         }
01274 
01275         //set mail params (from, fromName, smtp)
01276         $this->_setMailParams( $oShop );
01277 
01278         // create messages
01279         $oSmarty = $this->_getSmarty();
01280 
01281         $this->setViewData( "product", $oAlarm->getArticle() );
01282         $this->setViewData( "oPriceAlarm", $oAlarm );
01283         $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01284         $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01285 
01286         // Process view data array through oxoutput processor
01287         $this->_processViewArray();
01288 
01289         $this->setRecipient( $sRecipient, $sRecipient );
01290         $this->setSubject( $oShop->oxshops__oxname->value );
01291 
01292         if ( $sBody === null ) {
01293             $sBody  = $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sPricealamrCustomerTemplate, true ) );
01294         }
01295 
01296         $this->setBody( $sBody );
01297 
01298         $this->addAddress( $sRecipient, $sRecipient );
01299         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01300 
01301         if ( $sReturnMailBody ) {
01302             return $this->getBody();
01303         } else {
01304             return $this->send();
01305         }
01306     }
01307 
01319     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01320     {
01321         $sBody = $this->getBody();
01322         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01323 
01324             $oFileUtils = oxUtilsFile::getInstance();
01325             $blReSetBody = false;
01326 
01327             // preparing imput
01328             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01329             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01330             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01331 
01332             if (is_array($matches) && count($matches)) {
01333                 $aImageCache = array();
01334                 $myUtils = oxUtils::getInstance();
01335                 $myUtilsObject = oxUtilsObject::getInstance();
01336 
01337                 foreach ($matches as $aImage) {
01338 
01339                     $image = $aImage[1];
01340                     $sFileName = '';
01341                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01342                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01343                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01344                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01345                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01346                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01347                     }
01348 
01349                     if ($sFileName && @is_file($sFileName)) {
01350                         $sCId = '';
01351                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01352                             $sCId = $aImageCache[$sFileName];
01353                         } else {
01354                             $sCId = $myUtilsObject->generateUID();
01355                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01356                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01357                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01358                                     $aImageCache[$sFileName] = $sCId;
01359                                 } else {
01360                                     $sCId = '';
01361                                 }
01362                             }
01363                         }
01364                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01365                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01366                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01367                                 $blReSetBody = true;
01368                             }
01369                         }
01370                     }
01371                 }
01372             }
01373 
01374             if ( $blReSetBody ) {
01375                 $this->setBody( $sBody );
01376             }
01377         }
01378     }
01379 
01387     public function setSubject( $sSubject = null )
01388     {
01389         // A. HTML entites in subjects must be replaced
01390         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01391 
01392         $this->set( "Subject", $sSubject );
01393     }
01394 
01400     public function getSubject()
01401     {
01402         return $this->Subject;
01403     }
01404 
01414     public function setBody( $sBody = null, $blClearSid = true )
01415     {
01416         if ( $blClearSid ) {
01417             $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
01418         }
01419 
01420         $this->set( "Body", $sBody );
01421     }
01422 
01428     public function getBody()
01429     {
01430         return $this->Body;
01431     }
01432 
01442     public function setAltBody( $sAltBody = null, $blClearSid = true )
01443     {
01444         if ( $blClearSid ) {
01445             $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
01446         }
01447 
01448         // A. alt body is used for plain text emails so we should eliminate HTML entities
01449         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01450 
01451         $this->set( "AltBody", $sAltBody );
01452     }
01453 
01459     public function getAltBody()
01460     {
01461         return $this->AltBody;
01462     }
01463 
01472     public function setRecipient( $sAddress = null, $sName = null )
01473     {
01474         try {
01475             parent::AddAddress( $sAddress, $sName );
01476 
01477             // copying values as original class does not allow to access recipients array
01478             $this->_aRecipients[] = array( $sAddress, $sName );
01479         } catch( Exception $oEx ) {
01480         }
01481     }
01482 
01490     public function getRecipient()
01491     {
01492         return $this->_aRecipients;
01493     }
01494 
01501     public function clearAllRecipients()
01502     {
01503         $this->_aRecipients = array();
01504         parent::clearAllRecipients();
01505     }
01506 
01518     public function setReplyTo( $sEmail = null, $sName = null )
01519     {
01520         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01521             $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01522         }
01523 
01524         $this->_aReplies[] = array( $sEmail, $sName );
01525 
01526         try {
01527             parent::addReplyTo( $sEmail, $sName );
01528         } catch( Exception $oEx ) {
01529         }
01530     }
01531 
01537     public function getReplyTo()
01538     {
01539         return $this->_aReplies;
01540     }
01541 
01547     public function clearReplyTos()
01548     {
01549         $this->_aReplies = array();
01550         parent::clearReplyTos();
01551     }
01552 
01561     public function setFrom( $sFromAdress, $sFromName = null )
01562     {
01563         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01564         // this is simple but must work
01565         // dodger Task #1532 field "From" in emails from shops
01566         $sFromAdress = substr($sFromAdress, 0, 150);
01567         $sFromName   = substr($sFromName, 0, 150);
01568 
01569         try {
01570             parent::setFrom( $sFromAdress, $sFromName );
01571         } catch( Exception $oEx ) {
01572         }
01573     }
01574 
01580     public function getFrom()
01581     {
01582         return $this->From;
01583     }
01584 
01590     public function getFromName()
01591     {
01592         return $this->FromName;
01593     }
01594 
01603     public function setCharSet( $sCharSet = null )
01604     {
01605         if ( $sCharSet ) {
01606             $this->_sCharSet = $sCharSet;
01607         } else {
01608             $this->_sCharSet = oxLang::getInstance()->translateString( "charset" );
01609         }
01610         $this->set( "CharSet", $this->_sCharSet );
01611     }
01612 
01620     public function setMailer( $sMailer = null )
01621     {
01622         $this->set( "Mailer", $sMailer );
01623     }
01624 
01630     public function getMailer()
01631     {
01632         return $this->Mailer;
01633     }
01634 
01642     public function setHost( $sHost = null )
01643     {
01644         $this->set( "Host", $sHost );
01645     }
01646 
01652     public function getErrorInfo()
01653     {
01654         return $this->ErrorInfo;
01655     }
01656 
01665     public function setMailWordWrap( $iWordWrap = null )
01666     {
01667         $this->set( "WordWrap", $iWordWrap );
01668     }
01669 
01677     public function setUseInlineImages( $blUseImages = null )
01678     {
01679         $this->_blInlineImgEmail = $blUseImages;
01680     }
01681 
01692     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01693     {
01694         $sFullPath = $sAttPath . $sAttFile;
01695 
01696         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01697         $blResult = false;
01698 
01699         try {
01700              $blResult = parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01701         } catch( Exception $oEx ) {
01702         }
01703 
01704         return $blResult;
01705     }
01706 
01718     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01719     {
01720         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01721         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01722     }
01723 
01729     public function getAttachments()
01730     {
01731         return $this->_aAttachments;
01732     }
01733 
01739     public function clearAttachments()
01740     {
01741         $this->_aAttachments = array();
01742         return parent::clearAttachments();
01743     }
01744 
01754     public function headerLine($sName, $sValue)
01755     {
01756         if (stripos($sName, 'X-') !== false) {
01757             return;
01758         }
01759         return parent::headerLine($sName, $sValue);
01760     }
01761 
01767     protected function _getUseInlineImages()
01768     {
01769         return $this->_blInlineImgEmail;
01770     }
01771 
01777     protected function _sendMailErrorMsg()
01778     {
01779         // build addresses
01780         $sToAdress  = "";
01781         $sToName    = "";
01782 
01783         $aRecipients = $this->getRecipient();
01784 
01785         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01786 
01787         foreach ( $aRecipients as $aEMail ) {
01788             $sOwnerMessage .= $aEMail[0];
01789             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01790             $sOwnerMessage .= " \n ";
01791         }
01792         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01793 
01794         // shop info
01795         $oShop = $this->_getShop();
01796 
01797         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01798 
01799         return $blRet;
01800     }
01801 
01811     protected function _addUserInfoOrderEMail( $oOrder )
01812     {
01813         return $oOrder;
01814     }
01815 
01825     protected function _addUserRegisterEmail( $oUser )
01826     {
01827         return $oUser;
01828     }
01829 
01839     protected function _addForgotPwdEmail( $oShop )
01840     {
01841         return $oShop;
01842     }
01843 
01853     protected function _addNewsletterDbOptInMail( $oUser )
01854     {
01855         return $oUser;
01856     }
01857 
01863     protected function _clearMailer()
01864     {
01865         $this->clearAllRecipients();
01866         $this->clearReplyTos();
01867         $this->clearAttachments();
01868 
01869         //workaround for phpmailer as it doesn't cleanup as it should
01870         $this->error_count = 0;
01871         $this->ErrorInfo   = '';
01872     }
01873 
01881     protected function _setMailParams( $oShop = null )
01882     {
01883         $this->_clearMailer();
01884 
01885         if ( !$oShop ) {
01886             $oShop = $this->_getShop();
01887         }
01888 
01889         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01890         $this->setSmtp( $oShop );
01891     }
01892 
01902     protected function _getShop( $iLangId = null, $iShopId = null )
01903     {
01904 
01905         if ( isset( $this->_oShop ) ) {
01906             return $this->_oShop;
01907         }
01908 
01909         $myConfig = $this->getConfig();
01910 
01911         if ( $iLangId === null ) {
01912             $oShop = $myConfig->getActiveShop();
01913         } else {
01914             $oShop = oxNew( 'oxshop' );
01915             $oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01916         }
01917 
01918         return $this->_oShop = $oShop;
01919     }
01920 
01929     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01930     {
01931         $this->set( "SMTPAuth", true );
01932         $this->set( "Username", $sUserName );
01933         $this->set( "Password", $sUserPassword );
01934     }
01935 
01943     protected function _setSmtpDebug( $blDebug = null )
01944     {
01945         $this->set( "SMTPDebug", $blDebug );
01946     }
01947 
01953     protected function _setMailerPluginDir()
01954     {
01955         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
01956     }
01957 
01964     protected function _makeOutputProcessing()
01965     {
01966         $oOutput = oxNew( "oxoutput" );
01967         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01968         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01969         $oOutput->processEmail( $this );
01970     }
01971 
01977     protected function _sendMail()
01978     {
01979         $blResult = false;
01980         try {
01981              $blResult = parent::send();
01982         } catch( Exception $oEx ) {
01983         }
01984 
01985         return $blResult;
01986     }
01987 
01988 
01994     protected function _processViewArray()
01995     {
01996         $oSmarty = $this->_getSmarty();
01997         $oOutputProcessor = oxNew( "oxoutput" );
01998 
01999         // processing all setted view data
02000         foreach ( $this->_aViewData as $sKey => $sValue ) {
02001             $oSmarty->assign( $sKey, $sValue );
02002         }
02003 
02004         // processing assigned smarty variables
02005         $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02006 
02007         foreach ( $aNewSmartyArray as $key => $val ) {
02008             $oSmarty->assign( $key, $val );
02009         }
02010     }
02011 
02017     public function getCharset()
02018     {
02019         if ( !$this->_sCharSet ) {
02020             return oxLang::getInstance()->translateString("charset");
02021         } else {
02022             return $this->CharSet;
02023         }
02024     }
02025 
02031     public function getShop()
02032     {
02033         return $this->_getShop();
02034     }
02035 
02043     public function setShop( $oShop )
02044     {
02045         $this->_oShop = $oShop;
02046     }
02047 
02053     public function getViewConfig()
02054     {
02055         return $this->getConfig()->getActiveView()->getViewConfig();
02056     }
02057 
02063     public function getView()
02064     {
02065         return $this->getConfig()->getActiveView();
02066     }
02067 
02073     public function getCurrency()
02074     {
02075         $oConfig = oxConfig::getInstance();
02076 
02077         return $oConfig->getActShopCurrencyObject();
02078     }
02079 
02088     public function setViewData( $sKey, $sValue )
02089     {
02090         $this->_aViewData[$sKey] = $sValue;
02091     }
02092 
02098     public function getViewData()
02099     {
02100         return $this->_aViewData;
02101     }
02102 
02110     public function getViewDataItem( $sKey )
02111     {
02112         if ( isset($this->_aViewData[$sKey]) ) {
02113             return $this->_aViewData;
02114         }
02115     }
02116 
02124     public function setUser( $oUser)
02125     {
02126         $this->_aViewData["oUser"] = $oUser;
02127     }
02128 
02134     public function getUser()
02135     {
02136         return $this->_aViewData["oUser"];
02137     }
02138 
02139 }