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 $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
00098 
00104     protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
00105 
00111     protected $_sWishListTemplate = "email/html/wishlist.tpl";
00112 
00118     protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00119 
00125     protected $_sRegisterTemplate = "email/html/register.tpl";
00126 
00132     protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00133 
00139     protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00140 
00146     protected $_sOrderUserTemplate          = "email/html/order_cust.tpl";
00147 
00153     protected $_sOrderUserPlainTemplate     = "email/plain/order_cust.tpl";
00154 
00160     protected $_sOrderOwnerTemplate         = "email/html/order_owner.tpl";
00161 
00167     protected $_sOrderOwnerPlainTemplate    = "email/plain/order_owner.tpl";
00168 
00169     // #586A - additional templates for more customizable subjects
00170 
00176     protected $_sOrderUserSubjectTemplate   = "email/html/order_cust_subj.tpl";
00177 
00183     protected $_sOrderOwnerSubjectTemplate  = "email/html/order_owner_subj.tpl";
00184 
00190     protected $_sOwnerPricealarmTemplate    = "email/html/pricealarm_owner.tpl";
00191 
00197     protected $_sPricealamrCustomerTemplate    = "email_pricealarm_customer.tpl";
00198 
00204     protected $_aShops = array();
00205 
00211     protected $_blInlineImgEmail = null;
00212 
00218     protected $_aRecipients = array();
00219 
00225     protected $_aReplies = array();
00226 
00232     protected $_aAttachments = array();
00233 
00239     protected $_oSmarty = null;
00240 
00246     protected $_aViewData = array();
00247 
00253     protected $_oShop = null;
00254 
00260     protected $_sCharSet = null;
00261 
00265     public function __construct()
00266     {
00267         //enabling exception handling in phpmailer class
00268         parent::__construct( true );
00269 
00270         $myConfig = $this->getConfig();
00271 
00272         $this->_setMailerPluginDir();
00273         $this->setSmtp();
00274 
00275         $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00276         $this->setMailWordWrap( 100 );
00277 
00278         $this->isHtml( true );
00279         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00280 
00281         $this->_getSmarty();
00282     }
00283 
00295     public function __call( $sMethod, $aArgs )
00296     {
00297         if ( defined( 'OXID_PHP_UNIT' ) ) {
00298             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00299                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00300             }
00301             if ( method_exists( $this, $sMethod)) {
00302                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00303             }
00304         }
00305 
00306         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00307     }
00308 
00314     public function getConfig()
00315     {
00316         if ( $this->_oConfig == null ) {
00317             $this->_oConfig = oxConfig::getInstance();
00318         }
00319 
00320         return $this->_oConfig;
00321     }
00322 
00330     public function setConfig( $oConfig )
00331     {
00332         $this->_oConfig = $oConfig;
00333     }
00334 
00335 
00341     protected function _getSmarty()
00342     {
00343         if ( $this->_oSmarty === null ) {
00344             $this->_oSmarty = oxUtilsView::getInstance()->getSmarty();
00345         }
00346 
00347         //setting default view
00348         $this->_oSmarty->assign( "oEmailView", $this );
00349 
00350         return $this->_oSmarty;
00351     }
00352 
00360     public function send()
00361     {
00362         // if no recipients found, skipping sending
00363         if ( count( $this->getRecipient() ) < 1 ) {
00364             return false;
00365         }
00366 
00367         $myConfig = $this->getConfig();
00368         $this->setCharSet();
00369 
00370         if ( $this->_getUseInlineImages() ) {
00371             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
00372                                    $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00373         }
00374 
00375         $this->_makeOutputProcessing();
00376 
00377         // try to send mail via SMTP
00378         if ( $this->getMailer() == 'smtp' ) {
00379             $blRet = $this->_sendMail();
00380 
00381             // if sending failed, try to send via mail()
00382             if ( !$blRet ) {
00383                 // failed sending via SMTP, sending notification to shop owner
00384                 $this->_sendMailErrorMsg();
00385 
00386                 // trying to send using standard mailer
00387                 $this->setMailer( 'mail' );
00388                 $blRet = $this->_sendMail();
00389             }
00390         } else {
00391             // sending mail via mail()
00392             $this->setMailer( 'mail' );
00393             $blRet = $this->_sendMail();
00394         }
00395 
00396         if ( !$blRet ) {
00397             // failed sending, giving up, trying to send notification to shop owner
00398             $this->_sendMailErrorMsg();
00399         }
00400 
00401         return $blRet;
00402     }
00403 
00412     protected function _setSmtpProtocol($sUrl)
00413     {
00414         $sProtocol = '';
00415         $sSmtpHost = $sUrl;
00416         $aMatch = array();
00417         if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00418             if ($aMatch[1]) {
00419                 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00420                     $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00421                 } else {
00422                     $sProtocol = $aMatch[1];
00423                 }
00424             }
00425             $sSmtpHost = $aMatch[2];
00426         }
00427 
00428         return $sProtocol.$sSmtpHost;
00429     }
00430 
00438     public function setSmtp( $oShop = null )
00439     {
00440         $myConfig = $this->getConfig();
00441         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00442 
00443         $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00444 
00445         if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00446             $this->setMailer( "mail" );
00447             return;
00448         }
00449 
00450         $this->setHost( $sSmtpUrl );
00451         $this->setMailer( "smtp" );
00452 
00453         if ( $oShop->oxshops__oxsmtpuser->value ) {
00454             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00455         }
00456 
00457         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00458             $this->_setSmtpDebug( true );
00459         }
00460     }
00461 
00469     protected function _isValidSmtpHost( $sSmtpHost )
00470     {
00471         $blIsSmtp = false;
00472         if ( $sSmtpHost ) {
00473             $sSmtpPort = $this->SMTP_PORT;
00474             $aMatch = array();
00475             if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00476                 $sSmtpHost = $aMatch[1];
00477                 $sSmtpPort = (int)$aMatch[3];
00478                 if (!$sSmtpPort) {
00479                     $sSmtpPort = $this->SMTP_PORT;
00480                 }
00481             }
00482             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00483                 // closing connection ..
00484                 fclose( $rHandle );
00485             }
00486         }
00487 
00488         return $blIsSmtp;
00489     }
00490 
00500     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00501     {
00502         $myConfig = $this->getConfig();
00503 
00504         // add user defined stuff if there is any
00505         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00506 
00507         $oShop = $this->_getShop();
00508         $this->_setMailParams( $oShop );
00509 
00510         $oUser = $oOrder->getOrderUser();
00511         $this->setUser( $oUser );
00512 
00513         // create messages
00514         $oSmarty = $this->_getSmarty();
00515         $this->setViewData( "order", $oOrder);
00516 
00517         if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
00518             $this->setViewData( "blShowReviewLink", true );
00519         }
00520 
00521         // Process view data array through oxoutput processor
00522         $this->_processViewArray();
00523 
00524         $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00525         $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00526 
00527         // #586A
00528         if ( $sSubject === null ) {
00529             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00530                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00531             } else {
00532                 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00533             }
00534         }
00535 
00536         $this->setSubject( $sSubject );
00537 
00538         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00539 
00540         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00541         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00542 
00543         $blSuccess = $this->send();
00544 
00545         return $blSuccess;
00546     }
00547 
00557     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00558     {
00559         $myConfig = $this->getConfig();
00560 
00561         $oShop = $this->_getShop();
00562 
00563         // cleanup
00564         $this->_clearMailer();
00565 
00566         // add user defined stuff if there is any
00567         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00568 
00569         $oUser = $oOrder->getOrderUser();
00570         $this->setUser( $oUser );
00571 
00572         // send confirmation to shop owner
00573         // send not pretending from order user, as different email domain rise spam filters
00574         $this->setFrom( $oShop->oxshops__oxowneremail->value );
00575 
00576         $oLang = oxLang::getInstance();
00577         $iOrderLang = $oLang->getObjectTplLanguage();
00578 
00579         // if running shop language is different from admin lang. set in config
00580         // we have to load shop in config language
00581         if ( $oShop->getLanguage() != $iOrderLang ) {
00582             $oShop = $this->_getShop( $iOrderLang );
00583         }
00584 
00585         $this->setSmtp( $oShop );
00586 
00587         // create messages
00588         $oSmarty = $this->_getSmarty();
00589         $this->setViewData( "order", $oOrder );
00590 
00591         // Process view data array through oxoutput processor
00592         $this->_processViewArray();
00593 
00594         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00595         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00596 
00597         //Sets subject to email
00598         // #586A
00599         if ( $sSubject === null ) {
00600             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00601                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00602             } else {
00603                  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00604             }
00605         }
00606 
00607         $this->setSubject( $sSubject );
00608         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00609 
00610         if ( $oUser->oxuser__oxusername->value != "admin" ) {
00611             $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00612             $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00613         }
00614 
00615         $blSuccess = $this->send();
00616 
00617         // add user history
00618         $oRemark = oxNew( "oxremark" );
00619         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00620         $oRemark->oxremark__oxparentid  = new oxField($oUser->getId(), oxField::T_RAW);
00621         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00622         $oRemark->save();
00623 
00624 
00625         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00626             oxUtils::getInstance()->showMessageAndExit( "" );
00627         }
00628 
00629         return $blSuccess;
00630     }
00631 
00641     public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00642     {
00643         // setting content ident
00644 
00645         $this->setViewData( "contentident", "oxregisteraltemail" );
00646         $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00647 
00648         // sending email
00649         return $this->sendRegisterEmail( $oUser, $sSubject );
00650     }
00651 
00661     public function sendRegisterEmail( $oUser, $sSubject = null )
00662     {
00663         // add user defined stuff if there is any
00664         $oUser = $this->_addUserRegisterEmail( $oUser );
00665 
00666         // shop info
00667         $oShop = $this->_getShop();
00668 
00669         //set mail params (from, fromName, smtp )
00670         $this->_setMailParams( $oShop );
00671 
00672         // create messages
00673         $oSmarty = $this->_getSmarty();
00674         $this->setUser( $oUser );
00675 
00676         // Process view data array through oxoutput processor
00677         $this->_processViewArray();
00678 
00679         $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00680         $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00681 
00682         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00683 
00684         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00685 
00686         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00687         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00688 
00689         return $this->send();
00690     }
00691 
00701     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00702     {
00703         $myConfig = $this->getConfig();
00704         $oDb = oxDb::getDb();
00705 
00706         // shop info
00707         $oShop = $this->_getShop();
00708 
00709         // add user defined stuff if there is any
00710         $oShop = $this->_addForgotPwdEmail( $oShop );
00711 
00712         //set mail params (from, fromName, smtp)
00713         $this->_setMailParams( $oShop );
00714 
00715         // user
00716         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00717         $sOrder = "";
00718         if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00719             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00720         } else {
00721             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00722         }
00723 
00724         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00725 
00726         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00727             $oUser = oxNew( 'oxuser' );
00728             if ( $oUser->load($sOxId) ) {
00729                 // create messages
00730                 $oSmarty = $this->_getSmarty();
00731                 $this->setUser( $oUser );
00732 
00733                 // Process view data array through oxoutput processor
00734                 $this->_processViewArray();
00735 
00736                 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00737 
00738                 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00739 
00740                 //sets subject of email
00741                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00742 
00743                 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00744 
00745                 $this->setRecipient( $sEmailAddress, $sFullName );
00746                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00747 
00748                 if ( !$this->send() ) {
00749                     return -1; // failed to send
00750                 }
00751                 return true; // success
00752             }
00753         }
00754 
00755         return false; // user with this email not found
00756     }
00757 
00768     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00769     {
00770 
00771         // shop info
00772         $oShop = $this->_getShop();
00773 
00774         //set mail params (from, fromName, smtp)
00775         $this->_setMailParams( $oShop );
00776 
00777         $this->setBody( $sMessage );
00778         $this->setSubject( $sSubject );
00779 
00780         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00781         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00782         $this->setReplyTo( $sEmailAddress, "" );
00783 
00784         return $this->send();
00785     }
00786 
00796     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00797     {
00798         $oLang = oxLang::getInstance();
00799 
00800         // add user defined stuff if there is any
00801         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00802 
00803         // shop info
00804         $oShop = $this->_getShop();
00805 
00806         //set mail params (from, fromName, smtp)
00807         $this->_setMailParams( $oShop );
00808 
00809         // create messages
00810         $oSmarty = $this->_getSmarty();
00811         $sConfirmCode = md5($oUser->oxuser__oxusername->value.$oUser->oxuser__oxpasssalt->value);
00812         $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value, $sConfirmCode ) );
00813         $this->setUser( $oUser );
00814 
00815         // Process view data array through oxoutput processor
00816         $this->_processViewArray();
00817 
00818         $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00819         $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00820         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00821 
00822         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00823 
00824         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00825         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00826         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00827 
00828         return $this->send();
00829     }
00830 
00839     protected function _getNewsSubsLink( $sId, $sConfirmCode = null )
00840     {
00841         $myConfig = $this->getConfig();
00842         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00843 
00844         $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
00845         $sUrl.= ( $iActShopLang ) ? '&amp;lang='.$iActShopLang : "";
00846         $sUrl.= ( $sConfirmCode ) ? '&amp;confirm='.$sConfirmCode : "";
00847         return $sUrl;
00848     }
00849 
00860     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00861     {
00862         // shop info
00863         $oShop = $this->_getShop();
00864 
00865         //set mail params (from, fromName, smtp)
00866         $this->_setMailParams( $oShop );
00867 
00868         $sBody = $oNewsLetter->getHtmlText();
00869 
00870         if ( !empty($sBody) ) {
00871             $this->setBody( $sBody );
00872             $this->setAltBody( $oNewsLetter->getPlainText() );
00873         } else {
00874             $this->isHtml( false );
00875             $this->setBody( $oNewsLetter->getPlainText() );
00876         }
00877 
00878         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00879 
00880         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00881         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00882         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00883 
00884         return $this->send();
00885     }
00886 
00896     public function sendSuggestMail( $oParams, $oProduct )
00897     {
00898         $myConfig = $this->getConfig();
00899 
00900         //sets language of shop
00901         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00902 
00903         // shop info
00904         $oShop = $this->_getShop( $iCurrLang );
00905 
00906         //sets language to article
00907         if ( $oProduct->getLanguage() != $iCurrLang ) {
00908             $oProduct->setLanguage( $iCurrLang );
00909             $oProduct->load( $oProduct->getId() );
00910         }
00911 
00912         // mailer stuff
00913         // send not pretending from suggesting user, as different email domain rise spam filters
00914         $this->setFrom( $oShop->oxshops__oxinfoemail->value );
00915         $this->setSMTP();
00916 
00917         // create messages
00918         $oSmarty = $this->_getSmarty();
00919         $this->setViewData( "product", $oProduct );
00920         $this->setUser( $oParams );
00921 
00922         $sArticleUrl = $oProduct->getLink();
00923 
00924         //setting recommended user id
00925         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00926             $sArticleUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sArticleUrl );
00927             $sArticleUrl .= "su=" . $oActiveUser->getId();
00928         }
00929 
00930         $this->setViewData( "sArticleUrl", $sArticleUrl );
00931 
00932         // Process view data array through oxoutput processor
00933         $this->_processViewArray();
00934 
00935         $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00936         $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00937         $this->setSubject( $oParams->send_subject );
00938 
00939         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00940         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00941 
00942         return $this->send();
00943     }
00944 
00953     public function sendInviteMail( $oParams )
00954     {
00955         $myConfig = $this->getConfig();
00956 
00957         //sets language of shop
00958         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00959 
00960         // shop info
00961         $oShop = $this->_getShop( $iCurrLang );
00962 
00963         // mailer stuff
00964         $this->setFrom( $oParams->send_email, $oParams->send_name );
00965         $this->setSMTP();
00966 
00967         // create messages
00968         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00969         $this->setUser( $oParams );
00970 
00971         $sHomeUrl = $this->getViewConfig()->getHomeLink();
00972 
00973         //setting recommended user id
00974         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00975             $sHomeUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00976             $sHomeUrl .= "su=" . $oActiveUser->getId();
00977         }
00978 
00979         if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0  ) {
00980             foreach ( $oParams->rec_email as $sEmail ) {
00981                 if ( !empty( $sEmail ) ) {
00982                     $sRegisterUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00983                     //setting recipient user email
00984                     $sRegisterUrl .= "re=" . md5($sEmail);
00985                     $this->setViewData( "sHomeUrl", $sRegisterUrl );
00986 
00987                     // Process view data array through oxoutput processor
00988                     $this->_processViewArray();
00989 
00990                     $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00991 
00992                     $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00993                     $this->setSubject( $oParams->send_subject );
00994 
00995                     $this->setRecipient( $sEmail );
00996                     $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00997                     $this->send();
00998                     $this->clearAllRecipients();
00999                 }
01000             }
01001             return true;
01002         }
01003 
01004         return false;
01005     }
01006 
01016     public function sendSendedNowMail( $oOrder, $sSubject = null )
01017     {
01018         $myConfig = $this->getConfig();
01019 
01020         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01021 
01022         // shop info
01023         $oShop = $this->_getShop( $iOrderLang );
01024 
01025         //set mail params (from, fromName, smtp)
01026         $this->_setMailParams( $oShop );
01027 
01028         //create messages
01029         $oLang = oxLang::getInstance();
01030         $oSmarty = $this->_getSmarty();
01031         $this->setViewData( "order", $oOrder );
01032         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01033 
01034         if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
01035             $this->setViewData( "blShowReviewLink", true );
01036             //deprecated var
01037             $oUser = oxNew( 'oxuser' );
01038             $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01039         }
01040 
01041         // Process view data array through oxoutput processor
01042         $this->_processViewArray();
01043 
01044         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01045         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01046         //V send email in order language
01047         $iOldTplLang = $oLang->getTplLanguage();
01048         $iOldBaseLang = $oLang->getTplLanguage();
01049         $oLang->setTplLanguage( $iOrderLang );
01050         $oLang->setBaseLanguage( $iOrderLang );
01051 
01052         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01053         // force non admin to get correct paths (tpl, img)
01054         $myConfig->setAdminMode( false );
01055         $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
01056         $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
01057         $myConfig->setAdminMode( true );
01058         $oLang->setTplLanguage( $iOldTplLang );
01059         $oLang->setBaseLanguage( $iOldBaseLang );
01060         // set it back
01061         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01062 
01063         //Sets subject to email
01064         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01065 
01066         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01067 
01068         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01069         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01070 
01071         return $this->send();
01072     }
01073 
01083     public function sendDownloadLinksMail( $oOrder, $sSubject = null )
01084     {
01085         $myConfig = $this->getConfig();
01086 
01087         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01088 
01089         // shop info
01090         $oShop = $this->_getShop( $iOrderLang );
01091 
01092         //set mail params (from, fromName, smtp)
01093         $this->_setMailParams( $oShop );
01094 
01095         //create messages
01096         $oLang = oxLang::getInstance();
01097         $oSmarty = $this->_getSmarty();
01098         $this->setViewData( "order", $oOrder );
01099         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01100 
01101         //deprecated var
01102         $oUser = oxNew( 'oxuser' );
01103         $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01104 
01105         // Process view data array through oxoutput processor
01106         $this->_processViewArray();
01107 
01108         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01109         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01110         //V send email in order language
01111         $iOldTplLang = $oLang->getTplLanguage();
01112         $iOldBaseLang = $oLang->getTplLanguage();
01113         $oLang->setTplLanguage( $iOrderLang );
01114         $oLang->setBaseLanguage( $iOrderLang );
01115 
01116         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01117         // force non admin to get correct paths (tpl, img)
01118         $myConfig->setAdminMode( false );
01119         $this->setBody( $oSmarty->fetch( $this->_sSendDownloadsTemplate ) );
01120         $this->setAltBody( $oSmarty->fetch( $this->_sSendDownloadsTemplatePlain ) );
01121         $myConfig->setAdminMode( true );
01122         $oLang->setTplLanguage( $iOldTplLang );
01123         $oLang->setBaseLanguage( $iOldBaseLang );
01124         // set it back
01125         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01126 
01127         //Sets subject to email
01128         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString("EMAIL_SENDDOWNLOADS_SUBJECT") );
01129 
01130         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01131 
01132         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01133         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01134 
01135         return $this->send();
01136     }
01137 
01152     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01153     {
01154         // shop info
01155         $oShop = $this->_getShop();
01156 
01157         //set mail params (from, fromName, smtp)
01158         $this->_setMailParams( $oShop );
01159 
01160         $this->setBody( $sMessage );
01161         $this->setSubject( $sSubject );
01162 
01163         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01164         $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01165 
01166         $this->setFrom( $sEmailAddress, "" );
01167         $this->setReplyTo( $sEmailAddress, "" );
01168 
01169         //attaching files
01170         $blAttashSucc = true;
01171         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
01172         foreach ( $aAttFiles as $iNum => $sAttFile ) {
01173             $sFullPath = $sAttPath . $sAttFile;
01174             if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
01175                 $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
01176             } else {
01177                 $blAttashSucc = false;
01178                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
01179             }
01180         }
01181 
01182         if ( !$blAttashSucc ) {
01183             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
01184             $this->clearAttachments();
01185             return false;
01186         }
01187 
01188         $aStatus[] = 3;     //"Mailing backup files ...";
01189         $blSend = $this->send();
01190         $this->clearAttachments();
01191 
01192         return $blSend;
01193     }
01194 
01205     public function sendEmail( $sTo, $sSubject, $sBody )
01206     {
01207         //set mail params (from, fromName, smtp)
01208         $this->_setMailParams();
01209 
01210         if ( is_array($sTo) ) {
01211             foreach ($sTo as $sAddress) {
01212                 $this->setRecipient( $sAddress, "" );
01213                 $this->setReplyTo( $sAddress, "" );
01214             }
01215         } else {
01216             $this->setRecipient( $sTo, "" );
01217             $this->setReplyTo( $sTo, "" );
01218         }
01219 
01220         //may be changed later
01221         $this->isHtml( false );
01222 
01223         $this->setSubject( $sSubject );
01224         $this->setBody( $sBody );
01225 
01226         return $this->send();
01227     }
01228 
01237     public function sendStockReminder( $aBasketContents, $sSubject = null )
01238     {
01239         $blSend = false;
01240 
01241         $oArticleList = oxNew( "oxarticlelist" );
01242         $oArticleList->loadStockRemindProducts( $aBasketContents );
01243 
01244         // nothing to remind?
01245         if ( $oArticleList->count() ) {
01246             $oShop = $this->_getShop();
01247 
01248             //set mail params (from, fromName, smtp... )
01249             $this->_setMailParams( $oShop );
01250             $oLang = oxLang::getInstance();
01251 
01252             $oSmarty = $this->_getSmarty();
01253             $this->setViewData( "articles", $oArticleList );
01254 
01255             // Process view data array through oxoutput processor
01256             $this->_processViewArray();
01257 
01258             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01259             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01260             $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01261             $this->setAltBody( "" );
01262             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01263 
01264             $blSend = $this->send();
01265         }
01266 
01267         return $blSend;
01268     }
01269 
01278     public function sendWishlistMail( $oParams )
01279     {
01280         $myConfig = $this->getConfig();
01281 
01282         $this->_clearMailer();
01283 
01284         // shop info
01285         $oShop = $this->_getShop();
01286 
01287         // mailer stuff
01288         $this->setFrom( $oParams->send_email, $oParams->send_name );
01289         $this->setSMTP();
01290 
01291         // create messages
01292         $oSmarty = $this->_getSmarty();
01293         $this->setUser( $oParams );
01294 
01295         // Process view data array through oxoutput processor
01296         $this->_processViewArray();
01297 
01298         $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01299         $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01300         $this->setSubject( $oParams->send_subject );
01301 
01302         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01303         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01304 
01305         return $this->send();
01306     }
01307 
01318     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01319     {
01320         $this->_clearMailer();
01321         $oShop = $this->_getShop();
01322 
01323         //set mail params (from, fromName, smtp)
01324         $this->_setMailParams( $oShop );
01325 
01326         $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01327 
01328         $oArticle = oxNew( "oxarticle" );
01329         $oArticle->setSkipAbPrice( true );
01330         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01331         $oLang = oxLang::getInstance();
01332 
01333         // create messages
01334         $oSmarty = $this->_getSmarty();
01335         $this->setViewData( "product", $oArticle );
01336         $this->setViewData( "email", $aParams['email']);
01337         $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01338 
01339         // Process view data array through oxoutput processor
01340         $this->_processViewArray();
01341 
01342         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01343         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01344         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01345         $this->setFrom( $aParams['email'], "" );
01346         $this->setReplyTo( $aParams['email'], "" );
01347 
01348         return $this->send();
01349     }
01350 
01362     public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01363     {
01364         $this->_clearMailer();
01365 
01366         $oShop = $this->_getShop();
01367 
01368         if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01369             $oShop = oxNew( "oxshop" );
01370             $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01371             $this->setShop( $oShop );
01372         }
01373 
01374         //set mail params (from, fromName, smtp)
01375         $this->_setMailParams( $oShop );
01376 
01377         // create messages
01378         $oSmarty = $this->_getSmarty();
01379 
01380         $this->setViewData( "product", $oAlarm->getArticle() );
01381         $this->setViewData( "oPriceAlarm", $oAlarm );
01382         $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01383         $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01384 
01385         // Process view data array through oxoutput processor
01386         $this->_processViewArray();
01387 
01388         $this->setRecipient( $sRecipient, $sRecipient );
01389         $this->setSubject( $oShop->oxshops__oxname->value );
01390 
01391         if ( $sBody === null ) {
01392             $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
01393         }
01394 
01395         $this->setBody( $sBody );
01396 
01397         $this->addAddress( $sRecipient, $sRecipient );
01398         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01399 
01400         if ( $sReturnMailBody ) {
01401             return $this->getBody();
01402         } else {
01403             return $this->send();
01404         }
01405     }
01406 
01418     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01419     {
01420         $sBody = $this->getBody();
01421         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01422 
01423             $oFileUtils = oxUtilsFile::getInstance();
01424             $blReSetBody = false;
01425 
01426             // preparing imput
01427             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01428             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01429             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01430 
01431             if (is_array($matches) && count($matches)) {
01432                 $aImageCache = array();
01433                 $myUtils = oxUtils::getInstance();
01434                 $myUtilsObject = oxUtilsObject::getInstance();
01435                 $oImgGenerator = oxNew( "oxDynImgGenerator" );
01436 
01437                 foreach ($matches as $aImage) {
01438 
01439                     $image = $aImage[1];
01440                     $sFileName = '';
01441                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01442                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01443                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01444                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01445                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01446                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01447                     }
01448 
01449                     if ( $sFileName && !@is_readable( $sFileName ) ) {
01450                         $sFileName = $oImgGenerator->getImagePath( $sFileName );
01451                     }
01452 
01453                     if ( $sFileName ) {
01454                         $sCId = '';
01455                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01456                             $sCId = $aImageCache[$sFileName];
01457                         } else {
01458                             $sCId = $myUtilsObject->generateUID();
01459                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01460                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01461                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01462                                     $aImageCache[$sFileName] = $sCId;
01463                                 } else {
01464                                     $sCId = '';
01465                                 }
01466                             }
01467                         }
01468                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01469                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01470                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01471                                 $blReSetBody = true;
01472                             }
01473                         }
01474                     }
01475                 }
01476             }
01477 
01478             if ( $blReSetBody ) {
01479                 $this->setBody( $sBody );
01480             }
01481         }
01482     }
01483 
01491     public function setSubject( $sSubject = null )
01492     {
01493         // A. HTML entites in subjects must be replaced
01494         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01495 
01496         $this->set( "Subject", $sSubject );
01497     }
01498 
01504     public function getSubject()
01505     {
01506         return $this->Subject;
01507     }
01508 
01518     public function setBody( $sBody = null, $blClearSid = true )
01519     {
01520         if ( $blClearSid ) {
01521             $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
01522         }
01523 
01524         $this->set( "Body", $sBody );
01525     }
01526 
01532     public function getBody()
01533     {
01534         return $this->Body;
01535     }
01536 
01546     public function setAltBody( $sAltBody = null, $blClearSid = true )
01547     {
01548         if ( $blClearSid ) {
01549             $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
01550         }
01551 
01552         // A. alt body is used for plain text emails so we should eliminate HTML entities
01553         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01554 
01555         $this->set( "AltBody", $sAltBody );
01556     }
01557 
01563     public function getAltBody()
01564     {
01565         return $this->AltBody;
01566     }
01567 
01576     public function setRecipient( $sAddress = null, $sName = null )
01577     {
01578         try {
01579             parent::AddAddress( $sAddress, $sName );
01580 
01581             // copying values as original class does not allow to access recipients array
01582             $this->_aRecipients[] = array( $sAddress, $sName );
01583         } catch( Exception $oEx ) {
01584         }
01585     }
01586 
01594     public function getRecipient()
01595     {
01596         return $this->_aRecipients;
01597     }
01598 
01605     public function clearAllRecipients()
01606     {
01607         $this->_aRecipients = array();
01608         parent::clearAllRecipients();
01609     }
01610 
01622     public function setReplyTo( $sEmail = null, $sName = null )
01623     {
01624         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01625             $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01626         }
01627 
01628         $this->_aReplies[] = array( $sEmail, $sName );
01629 
01630         try {
01631             parent::addReplyTo( $sEmail, $sName );
01632         } catch( Exception $oEx ) {
01633         }
01634     }
01635 
01641     public function getReplyTo()
01642     {
01643         return $this->_aReplies;
01644     }
01645 
01651     public function clearReplyTos()
01652     {
01653         $this->_aReplies = array();
01654         parent::clearReplyTos();
01655     }
01656 
01665     public function setFrom( $sFromAdress, $sFromName = null )
01666     {
01667         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01668         // this is simple but must work
01669         // dodger Task #1532 field "From" in emails from shops
01670         $sFromAdress = substr($sFromAdress, 0, 150);
01671         $sFromName   = substr($sFromName, 0, 150);
01672 
01673         try {
01674             parent::setFrom( $sFromAdress, $sFromName );
01675         } catch( Exception $oEx ) {
01676         }
01677     }
01678 
01684     public function getFrom()
01685     {
01686         return $this->From;
01687     }
01688 
01694     public function getFromName()
01695     {
01696         return $this->FromName;
01697     }
01698 
01707     public function setCharSet( $sCharSet = null )
01708     {
01709         if ( $sCharSet ) {
01710             $this->_sCharSet = $sCharSet;
01711         } else {
01712             $this->_sCharSet = oxLang::getInstance()->translateString( "charset" );
01713         }
01714         $this->set( "CharSet", $this->_sCharSet );
01715     }
01716 
01724     public function setMailer( $sMailer = null )
01725     {
01726         $this->set( "Mailer", $sMailer );
01727     }
01728 
01734     public function getMailer()
01735     {
01736         return $this->Mailer;
01737     }
01738 
01746     public function setHost( $sHost = null )
01747     {
01748         $this->set( "Host", $sHost );
01749     }
01750 
01756     public function getErrorInfo()
01757     {
01758         return $this->ErrorInfo;
01759     }
01760 
01769     public function setMailWordWrap( $iWordWrap = null )
01770     {
01771         $this->set( "WordWrap", $iWordWrap );
01772     }
01773 
01781     public function setUseInlineImages( $blUseImages = null )
01782     {
01783         $this->_blInlineImgEmail = $blUseImages;
01784     }
01785 
01796     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01797     {
01798         $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
01799         $blResult = false;
01800 
01801         try {
01802              $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
01803         } catch( Exception $oEx ) {
01804         }
01805 
01806         return $blResult;
01807     }
01808 
01820     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01821     {
01822         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01823         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01824     }
01825 
01831     public function getAttachments()
01832     {
01833         return $this->_aAttachments;
01834     }
01835 
01841     public function clearAttachments()
01842     {
01843         $this->_aAttachments = array();
01844         return parent::clearAttachments();
01845     }
01846 
01856     public function headerLine($sName, $sValue)
01857     {
01858         if (stripos($sName, 'X-') !== false) {
01859             return;
01860         }
01861         return parent::headerLine($sName, $sValue);
01862     }
01863 
01869     protected function _getUseInlineImages()
01870     {
01871         return $this->_blInlineImgEmail;
01872     }
01873 
01879     protected function _sendMailErrorMsg()
01880     {
01881         // build addresses
01882         $sToAdress  = "";
01883         $sToName    = "";
01884 
01885         $aRecipients = $this->getRecipient();
01886 
01887         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01888 
01889         foreach ( $aRecipients as $aEMail ) {
01890             $sOwnerMessage .= $aEMail[0];
01891             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01892             $sOwnerMessage .= " \n ";
01893         }
01894         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01895 
01896         // shop info
01897         $oShop = $this->_getShop();
01898 
01899         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01900 
01901         return $blRet;
01902     }
01903 
01913     protected function _addUserInfoOrderEMail( $oOrder )
01914     {
01915         return $oOrder;
01916     }
01917 
01927     protected function _addUserRegisterEmail( $oUser )
01928     {
01929         return $oUser;
01930     }
01931 
01941     protected function _addForgotPwdEmail( $oShop )
01942     {
01943         return $oShop;
01944     }
01945 
01955     protected function _addNewsletterDbOptInMail( $oUser )
01956     {
01957         return $oUser;
01958     }
01959 
01965     protected function _clearMailer()
01966     {
01967         $this->clearAllRecipients();
01968         $this->clearReplyTos();
01969         $this->clearAttachments();
01970 
01971         //workaround for phpmailer as it doesn't cleanup as it should
01972         $this->error_count = 0;
01973         $this->ErrorInfo   = '';
01974     }
01975 
01983     protected function _setMailParams( $oShop = null )
01984     {
01985         $this->_clearMailer();
01986 
01987         if ( !$oShop ) {
01988             $oShop = $this->_getShop();
01989         }
01990 
01991         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01992         $this->setSmtp( $oShop );
01993     }
01994 
02004     protected function _getShop( $iLangId = null, $iShopId = null )
02005     {
02006         if ( $iLangId === null && $iShopId === null ) {
02007             if ( isset( $this->_oShop ) ) {
02008                 return $this->_oShop;
02009             } else {
02010                 return $this->_oShop = $this->getConfig()->getActiveShop();
02011             }
02012         }
02013 
02014         $myConfig = $this->getConfig();
02015 
02016         $oShop = oxNew( 'oxshop' );
02017         if ( $iShopId !== null ) {
02018             $oShop->setShopId($iShopId);
02019         }
02020         if ( $iLangId !== null ) {
02021             $oShop->setLanguage($iLangId);
02022         }
02023         $oShop->load($myConfig->getShopId());
02024 
02025         return $oShop;
02026     }
02027 
02036     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
02037     {
02038         $this->set( "SMTPAuth", true );
02039         $this->set( "Username", $sUserName );
02040         $this->set( "Password", $sUserPassword );
02041     }
02042 
02050     protected function _setSmtpDebug( $blDebug = null )
02051     {
02052         $this->set( "SMTPDebug", $blDebug );
02053     }
02054 
02060     protected function _setMailerPluginDir()
02061     {
02062         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
02063     }
02064 
02071     protected function _makeOutputProcessing()
02072     {
02073         $oOutput = oxNew( "oxoutput" );
02074         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
02075         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
02076         $oOutput->processEmail( $this );
02077     }
02078 
02084     protected function _sendMail()
02085     {
02086         $blResult = false;
02087         try {
02088              $blResult = parent::send();
02089         } catch( Exception $oEx ) {
02090         }
02091 
02092         return $blResult;
02093     }
02094 
02095 
02101     protected function _processViewArray()
02102     {
02103         $oSmarty = $this->_getSmarty();
02104         $oOutputProcessor = oxNew( "oxoutput" );
02105 
02106         // processing all setted view data
02107         foreach ( $this->_aViewData as $sKey => $sValue ) {
02108             $oSmarty->assign( $sKey, $sValue );
02109         }
02110 
02111         // processing assigned smarty variables
02112         $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02113 
02114         foreach ( $aNewSmartyArray as $key => $val ) {
02115             $oSmarty->assign( $key, $val );
02116         }
02117     }
02118 
02124     public function getCharset()
02125     {
02126         if ( !$this->_sCharSet ) {
02127             return oxLang::getInstance()->translateString("charset");
02128         } else {
02129             return $this->CharSet;
02130         }
02131     }
02132 
02138     public function getShop()
02139     {
02140         return $this->_getShop();
02141     }
02142 
02150     public function setShop( $oShop )
02151     {
02152         $this->_oShop = $oShop;
02153     }
02154 
02160     public function getViewConfig()
02161     {
02162         return $this->getConfig()->getActiveView()->getViewConfig();
02163     }
02164 
02170     public function getView()
02171     {
02172         return $this->getConfig()->getActiveView();
02173     }
02174 
02180     public function getCurrency()
02181     {
02182         $oConfig = oxConfig::getInstance();
02183 
02184         return $oConfig->getActShopCurrencyObject();
02185     }
02186 
02195     public function setViewData( $sKey, $sValue )
02196     {
02197         $this->_aViewData[$sKey] = $sValue;
02198     }
02199 
02205     public function getViewData()
02206     {
02207         return $this->_aViewData;
02208     }
02209 
02217     public function getViewDataItem( $sKey )
02218     {
02219         if ( isset($this->_aViewData[$sKey]) ) {
02220             return $this->_aViewData;
02221         }
02222     }
02223 
02231     public function setUser( $oUser)
02232     {
02233         $this->_aViewData["oUser"] = $oUser;
02234     }
02235 
02241     public function getUser()
02242     {
02243         return $this->_aViewData["oUser"];
02244     }
02245 
02253     public function getOrderFileList( $sOrderId )
02254     {
02255         $oOrderList = oxNew('oxOrderFileList');
02256         $oOrderList->loadOrderFiles( $sOrderId );
02257 
02258         return $oOrderList;
02259     }
02260 
02261 }