oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006 
00007 
00013 class oxEmail extends phpmailer
00014 {
00020     public $SMTP_PORT = 25;
00021 
00027     protected $_sReminderMailTemplate = "email_owner_reminder_html.tpl";
00028 
00034     protected $_sOrderUserTemplate          = "email_order_cust_html.tpl";
00035 
00041     protected $_sOrderUserPlainTemplate     = "email_order_cust_plain.tpl";
00042 
00048     protected $_sOrderOwnerTemplate         = "email_order_owner_html.tpl";
00049 
00055     protected $_sOrderOwnerPlainTemplate    = "email_order_owner_plain.tpl";
00056 
00057     // #586A - additional templates for more customizable subjects
00058 
00064     protected $_sOrderUserSubjectTemplate   = "email_order_cust_subj.tpl";
00065 
00071     protected $_sOrderOwnerSubjectTemplate  = "email_order_owner_subj.tpl";
00072 
00078     protected $_sOwnerPricealarmTemplate    = "email_pricealarm_owner.tpl";
00079 
00085     protected $_oShop = null;
00086 
00092     protected $_blInlineImgEmail = null;
00093 
00099     protected $_aRecipients = array();
00100 
00106     protected $_aReplies = array();
00107 
00113     protected $_aAttachments = array();
00114 
00118     public function __construct()
00119     {
00120         $myConfig = $this->getConfig();
00121 
00122         $this->_setMailerPluginDir();
00123         $this->setSmtp();
00124 
00125         $this->setUseInlineImages( true );
00126         $this->setMailWordWrap( 100 );
00127 
00128         $this->isHtml( true );
00129         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00130     }
00131 
00143     public function __call( $sMethod, $aArgs )
00144     {
00145         if ( defined( 'OXID_PHP_UNIT' ) ) {
00146             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00147                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00148             }
00149             if ( method_exists( $this, $sMethod)) {
00150                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00151             }
00152         }
00153 
00154         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00155     }
00156 
00162     public function getConfig()
00163     {
00164         if ( $this->_oConfig == null ) {
00165             $this->_oConfig = oxConfig::getInstance();
00166         }
00167 
00168         return $this->_oConfig;
00169     }
00170 
00178     public function setConfig( $oConfig )
00179     {
00180         $this->_oConfig = $oConfig;
00181     }
00182 
00190     public function send()
00191     {
00192         $myConfig = $this->getConfig();
00193         $this->setCharSet();
00194 
00195         if ( $this->_getUseInlineImages() ) {
00196             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00197                                    $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00198         }
00199 
00200         $this->_makeOutputProcessing();
00201 
00202         // try to send mail via SMTP
00203         if ( $this->getMailer() == 'smtp' ) {
00204             $blRet = $this->_sendMail();
00205 
00206             // if sending failed, try to send via mail()
00207             if ( !$blRet ) {
00208                 $this->setMailer( 'mail' );
00209                 $blRet = $this->_sendMail();
00210             }
00211         } else {
00212             // sending mail via mail()
00213             $this->setMailer( 'mail' );
00214             $blRet = $this->_sendMail();
00215         }
00216 
00217         if ( !$blRet ) {
00218             // failed sending, giving up, trying to send notification to shop owner
00219             $this->_sendMailErrorMsg();
00220         }
00221 
00222         return $blRet;
00223     }
00224 
00232     public function setSmtp( $oShop = null )
00233     {
00234         $myConfig = $this->getConfig();
00235         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00236 
00237         if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00238             $this->setMailer( "mail" );
00239             return;
00240         }
00241 
00242         $this->setHost( $oShop->oxshops__oxsmtp->value );
00243         $this->setMailer( "smtp" );
00244 
00245         if ( $oShop->oxshops__oxsmtpuser->value ) {
00246             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00247         }
00248 
00249         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00250             $this->_setSmtpDebug( true );
00251         }
00252     }
00253 
00261     protected function _isValidSmtpHost( $sSmtpHost )
00262     {
00263         $blIsSmtp = false;
00264         if ( $sSmtpHost ) {
00265             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00266                 // closing connection ..
00267                 fclose( $rHandle );
00268             }
00269         }
00270 
00271         return $blIsSmtp;
00272     }
00273 
00282     public function sendOrderEmailToUser( $oOrder )
00283     {
00284         $myConfig = $this->getConfig();
00285 
00286         $sCustHTML  = $this->_sOrderUserTemplate;
00287         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00288 
00289         // add user defined stuff if there is any
00290         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00291 
00292         //set mail params (from, fromName, smtp)
00293         $oShop = $this->_getShop();
00294         $this->_setMailParams( $oShop );
00295 
00296         // P
00297         // setting some deprecated variables
00298         $oOrder->oDelSet = $oOrder->getDelSet();
00299 
00300         $oUser = $oOrder->getUser();
00301         // create messages
00302         $smarty = oxUtilsView::getInstance()->getSmarty();
00303         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00304         $smarty->assign( "order", $oOrder);
00305         $smarty->assign( "shop", $oShop );
00306         $smarty->assign( "oViewConf", $oShop );
00307         $smarty->assign( "user", $oUser );
00308         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00309         $smarty->assign( "basket", $oOrder->getBasket() );
00310         $smarty->assign( "payment", $oOrder->getPayment() );
00311         if ( $oUser ) {
00312             $smarty->assign( "reviewuser", $oUser->getReviewUserHash($oUser->getId()) );
00313         }
00314         $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00315 
00316         //deprecated vars
00317         $smarty->assign( "iswishlist", true);
00318         $smarty->assign( "isreview", true);
00319 
00320         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00321             $smarty->assign( "vouchers", $aVoucherList );
00322         }
00323 
00324         $oOutputProcessor = oxNew( "oxoutput" );
00325         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00326 
00327         foreach ( $aNewSmartyArray as $key => $val ) {
00328             $smarty->assign( $key, $val );
00329         }
00330 
00331         $this->setBody( $smarty->fetch( $sCustHTML) );
00332         $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00333 
00334         // #586A
00335         if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00336             $this->setSubject( $smarty->fetch( $this->_sOrderUserSubjectTemplate) );
00337         } else {
00338             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00339         }
00340 
00341         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00342 
00343         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00344         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00345 
00346         $blSuccess = $this->send();
00347 
00348         return $blSuccess;
00349     }
00350 
00359     public function sendOrderEmailToOwner( $oOrder )
00360     {
00361         $myConfig = $this->getConfig();
00362 
00363         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00364         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00365 
00366         // cleanup
00367         $this->_clearMailer();
00368 
00369         // add user defined stuff if there is any
00370         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00371 
00372         // send confirmation to shop owner
00373         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00374         $this->setFrom( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00375 
00376         $oLang = oxLang::getInstance();
00377         $iOrderLang = $oLang->getTplLanguage();
00378 
00379         $oShop = $this->_getShop();
00380 
00381         // if running shop language is different from admin lang. set in config
00382         // we have to load shop in config language
00383         if ( $oShop->getLanguage() != $iOrderLang ) {
00384             $oShop = $this->_getShop( $iOrderLang );
00385         }
00386 
00387         $this->setSmtp( $oShop );
00388 
00389         // create messages
00390         $smarty = oxUtilsView::getInstance()->getSmarty();
00391         $smarty->assign( "charset", $oLang->translateString("charset"));
00392         $smarty->assign( "order", $oOrder );
00393         $smarty->assign( "shop", $oShop );
00394         $smarty->assign( "oViewConf", $oShop );
00395         $smarty->assign( "user", $oOrder->getUser() );
00396         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00397         $smarty->assign( "basket", $oOrder->getBasket() );
00398         $smarty->assign( "payment", $oOrder->getPayment() );
00399 
00400         //deprecated var
00401         $smarty->assign( "iswishlist", true);
00402 
00403         if( $oOrder->getVoucherList() )
00404             $smarty->assign( "vouchers", $oOrder->getVoucherList() );
00405 
00406         $oOutputProcessor = oxNew( "oxoutput" );
00407         $aNewSmartyArray = $oOutputProcessor->processViewArray($smarty->get_template_vars(), "oxemail");
00408         foreach ($aNewSmartyArray as $key => $val)
00409             $smarty->assign( $key, $val );
00410 
00411         //path to admin message template file
00412         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00413 
00414         $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00415         $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00416 
00417         //Sets subject to email
00418         // #586A
00419         if ( $smarty->template_exists( $this->_sOrderOwnerSubjectTemplate) )
00420             $this->setSubject( $smarty->fetch( $this->_sOrderOwnerSubjectTemplate) );
00421         else
00422             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00423 
00424         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00425 
00426         if ( $oOrder->getUser()->oxuser__oxusername->value != "admin" )
00427             $this->setReplyTo( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00428 
00429         $blSuccess = $this->send();
00430 
00431         // add user history
00432         $oRemark = oxNew( "oxremark" );
00433         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00434         $oRemark->oxremark__oxparentid  = new oxField($oOrder->getUser()->getId(), oxField::T_RAW);
00435         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00436         $oRemark->save();
00437 
00438 
00439         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00440             exit();
00441         }
00442 
00443         return $blSuccess;
00444     }
00445 
00454     public function sendRegisterEmail( $oUser )
00455     {
00456         // add user defined stuff if there is any
00457         $oUser = $this->_addUserRegisterEmail( $oUser );
00458 
00459         // shop info
00460         $oShop = $this->_getShop();
00461 
00462         //set mail params (from, fromName, smtp )
00463         $this->_setMailParams( $oShop );
00464 
00465         // create messages
00466         $smarty = oxUtilsView::getInstance()->getSmarty();
00467         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00468         $smarty->assign( "shop", $oShop );
00469         $smarty->assign( "oViewConf", $oShop );
00470         $smarty->assign( "user", $oUser );
00471 
00472         $oOutputProcessor = oxNew( "oxoutput" );
00473         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00474 
00475         foreach ( $aNewSmartyArray as $key => $val ) {
00476             $smarty->assign( $key, $val );
00477         }
00478 
00479         $this->setBody( $smarty->fetch( "email_register_html.tpl") );
00480         $this->setAltBody( $smarty->fetch( "email_register_plain.tpl") );
00481 
00482         $this->setSubject( $oShop->oxshops__oxregistersubject->value );
00483 
00484         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00485 
00486         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00487         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00488 
00489         return $this->send();
00490     }
00491 
00500     public function sendForgotPwdEmail( $sEmailAddress )
00501     {
00502         $myConfig = $this->getConfig();
00503 
00504         // shop info
00505         $oShop = $this->_getShop();
00506 
00507         // add user defined stuff if there is any
00508         $oShop = $this->_addForgotPwdEmail( $oShop);
00509 
00510         //set mail params (from, fromName, smtp)
00511         $this->_setMailParams( $oShop );
00512 
00513         // user
00514         $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and
00515                     oxuser.oxusername = '$sEmailAddress' and oxuser.oxpassword != ''
00516                     order by oxshopid = '".$oShop->getId()."' desc";
00517 
00518         if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00519 
00520             $oUser = oxNew( 'oxuser' );
00521             if ( $oUser->load($sOxId) ) {
00522                 // create messages
00523                 $smarty = oxUtilsView::getInstance()->getSmarty();
00524                 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00525                 $smarty->assign( "shop", $oShop );
00526                 $smarty->assign( "oViewConf", $oShop );
00527                 $smarty->assign( "user", $oUser );
00528 
00529                 $oOutputProcessor = oxNew( "oxoutput" );
00530                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00531 
00532                 foreach ( $aNewSmartyArray as $key => $val ) {
00533                     $smarty->assign($key, $val);
00534                 }
00535 
00536                 $this->setBody( $smarty->fetch( "email_forgotpwd_html.tpl") );
00537                 $this->setAltBody( $smarty->fetch( "email_forgotpwd_plain.tpl") );
00538 
00539                 //sets subject of email
00540                 $this->setSubject( $oShop->oxshops__oxforgotpwdsubject->value );
00541 
00542                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00543 
00544                 $this->setRecipient( $sEmailAddress, $sFullName );
00545                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00546 
00547                 return $this->send();
00548             }
00549         }
00550 
00551         return false;
00552     }
00553 
00564     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00565     {
00566 
00567         // shop info
00568         $oShop = $this->_getShop();
00569 
00570         //set mail params (from, fromName, smtp)
00571         $this->_setMailParams( $oShop );
00572 
00573         $this->setBody( $sMessage );
00574         $this->setSubject( $sSubject );
00575 
00576         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00577         $this->setFrom( $sEmailAddress, "" );
00578         $this->setReplyTo( $sEmailAddress, "" );
00579 
00580         return $this->send();
00581     }
00582 
00591     public function sendNewsletterDbOptInMail( $oUser )
00592     {
00593 
00594         // add user defined stuff if there is any
00595         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00596 
00597         // shop info
00598         $oShop = $this->_getShop();
00599 
00600         //set mail params (from, fromName, smtp)
00601         $this->_setMailParams( $oShop );
00602 
00603         // create messages
00604         $smarty = oxUtilsView::getInstance()->getSmarty();
00605         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00606         $smarty->assign( "shop", $oShop );
00607         $smarty->assign( "oViewConf", $oShop );
00608         $smarty->assign( "user", $oUser );
00609 
00610         $oOutputProcessor = oxNew( "oxoutput" );
00611         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00612         foreach ( $aNewSmartyArray as $key => $val ) {
00613             $smarty->assign( $key, $val );
00614         }
00615 
00616         $this->setBody( $smarty->fetch("email_newsletteroptin_html.tpl") );
00617         $this->setAltBody( $smarty->fetch( "email_newsletteroptin_plain.tpl") );
00618         $this->setSubject( "Newsletter " . $oShop->oxshops__oxname->getRawValue() );
00619 
00620         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00621 
00622         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00623         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00624         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00625 
00626         return $this->send();
00627     }
00628 
00638     public function sendNewsletterMail( $oNewsLetter, $oUser )
00639     {
00640         // shop info
00641         $oShop = $this->_getShop();
00642 
00643         //set mail params (from, fromName, smtp)
00644         $this->_setMailParams( $oShop );
00645 
00646         $sBody = $oNewsLetter->getHtmlText();
00647 
00648         if ( !empty($sBody) ) {
00649             $this->setBody( $sBody );
00650             $this->setAltBody( $oNewsLetter->getPlainText() );
00651         } else {
00652             $this->isHtml( false );
00653             $this->setBody( $oNewsLetter->getPlainText() );
00654         }
00655 
00656         $this->setSubject( $oNewsLetter->oxnewsletter__oxtitle->value );
00657 
00658         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00659         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00660         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00661 
00662         return $this->send();
00663     }
00664 
00674     public function sendSuggestMail( $oParams, $oProduct )
00675     {
00676         $myConfig = $this->getConfig();
00677 
00678         //sets language of shop
00679         $iCurrLang = 0;
00680         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00681         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00682             $iCurrLang = $iActShopLang;
00683         }
00684 
00685         // shop info
00686         $oShop = $this->_getShop( $iCurrLang );
00687 
00688         //sets language to article
00689         if ( $oProduct->getLanguage() != $iCurrLang ) {
00690             $oProduct->setLanguage( $iCurrLang );
00691             $oProduct->load( $oProduct->getId() );
00692         }
00693 
00694         // mailer stuff
00695         $this->setFrom( $oParams->send_email, $oParams->send_name );
00696         $this->setSMTP();
00697 
00698         // create messages
00699         $smarty = oxUtilsView::getInstance()->getSmarty();
00700         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00701         $smarty->assign( "shop", $oShop );
00702         $smarty->assign( "oViewConf", $oShop );
00703         $smarty->assign( "userinfo", $oParams );
00704         $smarty->assign( "product", $oProduct );
00705 
00706         $oOutputProcessor = oxNew( "oxoutput" );
00707         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00708 
00709         foreach ( $aNewSmartyArray as $key => $val ) {
00710             $smarty->assign( $key, $val );
00711         }
00712 
00713         $this->setBody( $smarty->fetch( "email_suggest_html.tpl") );
00714         $this->setAltBody( $smarty->fetch( "email_suggest_plain.tpl") );
00715         $this->setSubject( $oParams->send_subject );
00716 
00717         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00718         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00719 
00720         return $this->send();
00721     }
00722 
00731     public function sendSendedNowMail( $oOrder )
00732     {
00733         $myConfig = $this->getConfig();
00734 
00735         $iOrderLang = 0;
00736         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00737             $iOrderLang = $oOrder->oxorder__oxlang->value;
00738         }
00739 
00740         // shop info
00741         $oShop = $this->_getShop( $iOrderLang );
00742 
00743         //set mail params (from, fromName, smtp)
00744         $this->_setMailParams( $oShop );
00745 
00746         //override default wrap
00747         //$this->setMailWordWrap( 0 );
00748 
00749         //create messages
00750         $oLang = oxLang::getInstance();
00751         $smarty = oxUtilsView::getInstance()->getSmarty();
00752         $smarty->assign( "charset", $oLang->translateString("charset"));
00753         $smarty->assign( "shop", $oShop );
00754         $smarty->assign( "oViewConf", $oShop );
00755         $smarty->assign( "order", $oOrder );
00756         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00757 
00758         //deprecated var
00759         $smarty->assign( "isreview", true);
00760 
00761         $oOutputProcessor = oxNew( "oxoutput" );
00762         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00763 
00764         foreach ( $aNewSmartyArray as $key => $val ) {
00765             $smarty->assign( $key, $val );
00766         }
00767 
00768         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00769         $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00770         //V send email in order language
00771         $iOldTplLang = $oLang->getTplLanguage();
00772         $iOldBaseLang = $oLang->getTplLanguage();
00773         $oLang->setTplLanguage( $iOrderLang );
00774         $oLang->setBaseLanguage( $iOrderLang );
00775 
00776         $smarty->security_settings['INCLUDE_ANY'] = true;
00777 
00778         //Sets path to template file
00779         $sPathToTemplate = $myConfig->getTemplateDir(false)."/";
00780 
00781         $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00782         $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00783         $oLang->setTplLanguage( $iOldTplLang );
00784         $oLang->setBaseLanguage( $iOldBaseLang );
00785         // set it back
00786         $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00787 
00788         //Sets subject to email
00789         $this->setSubject( $oShop->oxshops__oxsendednowsubject->value );
00790 
00791         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00792 
00793         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00794         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00795         return $this->send();
00796     }
00797 
00812     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00813     {
00814 
00815         /* P
00816         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00817         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00818         */
00819 
00820         // shop info
00821         $oShop = $this->_getShop();
00822 
00823         //set mail params (from, fromName, smtp)
00824         $this->_setMailParams( $oShop );
00825 
00826         $this->setBody( $sMessage );
00827         $this->setSubject( $sSubject );
00828 
00829         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00830 
00831         if ( !$sEmailAddress ) {
00832             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00833         }
00834 
00835         $this->setFrom( $sEmailAddress, "" );
00836         $this->setReplyTo( $sEmailAddress, "" );
00837 
00838         //attaching files
00839         $blAttashSucc = true;
00840         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00841         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00842             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00843                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00844             } else {
00845                 $blAttashSucc = false;
00846                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00847             }
00848         }
00849 
00850         if ( !$blAttashSucc ) {
00851             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00852             $this->clearAttachments();
00853             return false;
00854         }
00855 
00856         $aStatus[] = 3;     //"Mailing backup files ...";
00857         $blSend = $this->send();
00858         $this->clearAttachments();
00859 
00860         return $blSend;
00861     }
00862 
00873     public function sendEmail( $sTo, $sSubject, $sBody )
00874     {
00875         //set mail params (from, fromName, smtp)
00876         $this->_setMailParams();
00877 
00878         if ( is_array($sTo) ) {
00879             foreach ($sTo as $sAddress) {
00880                 $this->setRecipient( $sAddress, "" );
00881                 $this->setReplyTo( $sAddress, "" );
00882             }
00883         } else {
00884             $this->setRecipient( $sTo, "" );
00885             $this->setReplyTo( $sTo, "" );
00886         }
00887 
00888         //may be changed later
00889         $this->isHtml( false );
00890 
00891         $this->setSubject( $sSubject );
00892         $this->setBody( $sBody );
00893 
00894         return $this->send();
00895     }
00896 
00904     public function sendStockReminder( $aBasketContents )
00905     {
00906         $myConfig = $this->getConfig();
00907 
00908         $aRemindArticles = array();
00909         foreach ( $aBasketContents as $oBasketItem ) {
00910             $oArticle = $oBasketItem->getArticle();
00911              // reminder not set
00912             if ( !$oArticle->oxarticles__oxremindactive->value || $oArticle->oxarticles__oxremindactive->value > 1 ) {
00913                 continue;
00914             }
00915 
00916             // number or articles available is more
00917             if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00918                 continue;
00919             }
00920 
00921             $aRemindArticles[] = $oArticle;
00922             $oArticle->disableReminder();
00923         }
00924 
00925         // nothing to remind ...
00926         if ( !count( $aRemindArticles ) ) {
00927             return false;
00928         }
00929         $oShop = $this->_getShop();
00930 
00931         //set mail params (from, fromName, smtp... )
00932         $this->_setMailParams( $oShop );
00933         $oLang = oxLang::getInstance();
00934 
00935 
00936         $smarty = oxUtilsView::getInstance()->getSmarty();
00937         $smarty->assign( "charset", $oLang->translateString("charset"));
00938         $smarty->assign( "shop", $oShop );
00939         $smarty->assign( "oViewConf", $oShop );
00940         $smarty->assign( "articles", $aRemindArticles );
00941 
00942         //path to admin message template file
00943         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00944 
00945         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00946         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00947         $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00948         $this->setAltBody( "" );
00949         $this->setSubject( $oLang->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00950 
00951         return $this->send();
00952     }
00953 
00962     public function sendWishlistMail( $oParams )
00963     {
00964         $myConfig = $this->getConfig();
00965 
00966         $this->_clearMailer();
00967 
00968         // shop info
00969         $oShop = $this->_getShop();
00970 
00971         // mailer stuff
00972         $this->setFrom( $oParams->send_email, $oParams->send_name );
00973         $this->setSMTP();
00974 
00975         // create messages
00976         $smarty = oxUtilsView::getInstance()->getSmarty();
00977         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00978         $smarty->assign( "shop", $oShop );
00979         $smarty->assign( "oViewConf", $oShop );
00980         $smarty->assign( "userinfo", $oParams );
00981 
00982         $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
00983         $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
00984         $this->setSubject( $oParams->send_subject );
00985 
00986         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00987         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00988 
00989         return $this->send();
00990     }
00991 
01001     public function sendPriceAlarmNotification( $aParams, $oAlarm )
01002     {
01003         $this->_clearMailer();
01004         $oShop = $this->_getShop();
01005 
01006         //set mail params (from, fromName, smtp)
01007         $this->_setMailParams( $oShop );
01008 
01009         $iAlarmLang = $oShop->getLanguage();
01010 
01011         $oArticle = oxNew( "oxarticle" );
01012         $oArticle->setSkipAbPrice( true );
01013         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01014 
01015         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01016         $oLang = oxLang::getInstance();
01017 
01018         // create messages
01019         $smarty = oxUtilsView::getInstance()->getSmarty();
01020         $smarty->assign( "shop", $oShop );
01021         $smarty->assign( "oViewConf", $oShop );
01022         $smarty->assign( "product", $oArticle );
01023         $smarty->assign( "email", $aParams['email']);
01024         $smarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01025         $smarty->assign( "currency", $oCur );
01026 
01027         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01028         $sSubject = $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value;
01029         $this->setSubject( $sSubject );
01030         $this->setBody( $smarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01031         $this->setFrom( $aParams['email'], "" );
01032         $this->setReplyTo( $aParams['email'], "" );
01033 
01034         return $this->send();
01035     }
01036 
01048     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01049     {
01050         $sBody = $this->getBody();
01051         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01052 
01053             $oFileUtils = oxUtilsFile::getInstance();
01054             $blReSetBody = false;
01055 
01056             // preparing imput
01057             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01058             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01059             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01060 
01061             if (is_array($matches) && count($matches)) {
01062                 $aImageCache = array();
01063                 $myUtils = oxUtils::getInstance();
01064                 $myUtilsObject = oxUtilsObject::getInstance();
01065 
01066                 foreach ($matches as $aImage) {
01067 
01068                     $image = $aImage[1];
01069                     $sFileName = '';
01070                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01071                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01072                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01073                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01074                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01075                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01076                     }
01077 
01078                     if ($sFileName && @is_file($sFileName)) {
01079                         $sCId = '';
01080                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01081                             $sCId = $aImageCache[$sFileName];
01082                         } else {
01083                             $sCId = $myUtilsObject->generateUID();
01084                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01085                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01086                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01087                                     $aImageCache[$sFileName] = $sCId;
01088                                 } else {
01089                                     $sCId = '';
01090                                 }
01091                             }
01092                         }
01093                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01094                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01095                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01096                                 $blReSetBody = true;
01097                             }
01098                         }
01099                     }
01100                 }
01101             }
01102 
01103             if ( $blReSetBody ) {
01104                 $this->setBody( $sBody );
01105             }
01106         }
01107     }
01108 
01116     public function setSubject( $sSubject = null )
01117     {
01118         // A. HTML entites in subjects must be replaced
01119         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01120         $this->Subject = $sSubject;
01121     }
01122 
01128     public function getSubject()
01129     {
01130         return $this->Subject;
01131     }
01132 
01142     public function setBody( $sBody = null, $blClearSid = true )
01143     {
01144         if ( $blClearSid ) {
01145             $sBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01146         }
01147 
01148         $this->Body = $sBody;
01149     }
01150 
01156     public function getBody()
01157     {
01158         return $this->Body;
01159     }
01160 
01170     public function setAltBody( $sAltBody = null, $blClearSid = true )
01171     {
01172         if ( $blClearSid ) {
01173             $sAltBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01174         }
01175 
01176         // A. alt body is used for plain text emails so we should eliminate HTML entities
01177         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01178         $this->AltBody = $sAltBody;
01179     }
01180 
01186     public function getAltBody()
01187     {
01188         return $this->AltBody;
01189     }
01190 
01199     public function setRecipient( $sAddress = null, $sName = null )
01200     {
01201         // copying values as original class does not allow to access recipients array
01202         $this->_aRecipients[] = array( $sAddress, $sName );
01203 
01204         parent::AddAddress($sAddress, $sName );
01205     }
01206 
01214     public function getRecipient()
01215     {
01216         return $this->_aRecipients;
01217     }
01218 
01225     public function clearAllRecipients()
01226     {
01227         $this->_aRecipients = array();
01228         parent::clearAllRecipients();
01229     }
01230 
01242     public function setReplyTo( $sEmail = null, $sName = null )
01243     {
01244         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01245             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01246         }
01247 
01248         $this->_aReplies[] = array( $sEmail, $sName );
01249         parent::AddReplyTo( $sEmail, $sName );
01250     }
01251 
01257     public function getReplyTo()
01258     {
01259         return $this->_aReplies;
01260     }
01261 
01267     public function clearReplyTos()
01268     {
01269         $this->_aReplies = array();
01270         parent::clearReplyTos();
01271     }
01272 
01281     public function setFrom( $sFromAdress = null, $sFromName = null )
01282     {
01283         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01284         // this is simple but must work
01285         // dodger Task #1532 field "From" in emails from shops
01286         $this->From     = substr($sFromAdress, 0, 150);
01287         $this->FromName = substr($sFromName, 0, 150);
01288     }
01289 
01295     public function getFrom()
01296     {
01297         return $this->From;
01298     }
01299 
01305     public function getFromName()
01306     {
01307         return $this->FromName;
01308     }
01309 
01318     public function setCharSet( $sCharSet = null )
01319     {
01320         if ( !empty($sCharSet) ) {
01321             $this->CharSet = $sCharSet;
01322         } else {
01323             $this->CharSet = oxLang::getInstance()->translateString("charset");
01324         }
01325     }
01326 
01332     public function getCharSet()
01333     {
01334         return $this->CharSet;
01335     }
01336 
01344     public function setMailer( $sMailer = null )
01345     {
01346         $this->Mailer = $sMailer;
01347     }
01348 
01354     public function getMailer()
01355     {
01356         return $this->Mailer;
01357     }
01358 
01366     public function setHost( $sHost = null )
01367     {
01368         $this->Host = $sHost;
01369     }
01370 
01376     public function getErrorInfo()
01377     {
01378         return $this->ErrorInfo;
01379     }
01380 
01389     public function setMailWordWrap( $iWordWrap = null )
01390     {
01391         $this->WordWrap = $iWordWrap;
01392     }
01393 
01401     public function setUseInlineImages( $blUseImages = null )
01402     {
01403         $this->_blInlineImgEmail = $blUseImages;
01404     }
01405 
01416     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01417     {
01418         $sFullPath = $sAttPath . $sAttFile;
01419 
01420         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01421         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01422     }
01423 
01435     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01436     {
01437         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01438         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01439     }
01440 
01446     public function getAttachments()
01447     {
01448         return $this->_aAttachments;
01449     }
01450 
01456     public function clearAttachments()
01457     {
01458         $this->_aAttachments = array();
01459         return parent::ClearAttachments();
01460     }
01461 
01471     public function headerLine($sName, $sValue)
01472     {
01473         if (stripos($sName, 'X-') !== false) {
01474             return;
01475         }
01476         return parent::headerLine($sName, $sValue);
01477     }
01478 
01484     protected function _getUseInlineImages()
01485     {
01486         return $this->_blInlineImgEmail;
01487     }
01488 
01494     protected function _sendMailErrorMsg()
01495     {
01496         // build addresses
01497         $sToAdress  = "";
01498         $sToName    = "";
01499 
01500         $aRecipients = $this->getRecipient();
01501 
01502         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01503 
01504         foreach ( $aRecipients as $aEMail ) {
01505             $sOwnerMessage .= $aEMail[0];
01506             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01507             $sOwnerMessage .= " \n ";
01508         }
01509         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01510 
01511         // shop info
01512         $oShop = $this->_getShop();
01513 
01514         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01515 
01516         return $blRet;
01517     }
01518 
01528     protected function _addUserInfoOrderEMail( $oOrder )
01529     {
01530         return $oOrder;
01531     }
01532 
01542     protected function _addUserRegisterEmail( $oUser )
01543     {
01544         return $oUser;
01545     }
01546 
01556     protected function _addForgotPwdEmail( $oShop )
01557     {
01558         return $oShop;
01559     }
01560 
01570     protected function _addNewsletterDbOptInMail( $oUser )
01571     {
01572         return $oUser;
01573     }
01574 
01580     protected function _clearMailer()
01581     {
01582         $this->clearAllRecipients();
01583         $this->clearReplyTos();
01584         $this->clearAttachments();
01585 
01586         //workaround for phpmailer as it doesn't cleanup as it should
01587         $this->error_count = 0;
01588         $this->ErrorInfo   = '';
01589     }
01590 
01598     protected function _setMailParams( $oShop = null )
01599     {
01600         $this->_clearMailer();
01601 
01602         if ( !$oShop ) {
01603             $oShop = $this->_getShop();
01604         }
01605 
01606         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01607         $this->setSmtp( $oShop );
01608     }
01609 
01618     protected function _getShop( $iLangId = null )
01619     {
01620         $myConfig = $this->getConfig();
01621         if ( !isset($iLangId) ) {
01622             $iLangId = 0;
01623             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01624             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01625                 $iLangId = $iActShopLang;
01626             }
01627         }
01628         if ( isset($this->_oShop) && $this->_oShop ) {
01629             // if oShop already setted and reqesting oShop with same language as current oShop,
01630             // or wihtout lang param, return oShop object
01631             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01632                 return $this->_oShop;
01633             }
01634         }
01635 
01636         $this->_oShop = oxNew( 'oxshop' );
01637 
01638         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01639 
01640         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01641 
01642         $oView = $myConfig->getActiveView();
01643         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01644 
01645         return $this->_oShop;
01646     }
01647 
01656     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01657     {
01658         $this->SMTPAuth = true;
01659         $this->Username = $sUserName;
01660         $this->Password = $sUserPassword;
01661     }
01662 
01670     protected function _setSmtpDebug( $blDebug = null )
01671     {
01672         $this->SMTPDebug = $blDebug;
01673     }
01674 
01680     protected function _setMailerPluginDir()
01681     {
01682         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01683     }
01684 
01691     protected function _makeOutputProcessing()
01692     {
01693         $oOutput = oxNew( "oxoutput" );
01694         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01695         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01696         $oOutput->processEmail( $this );
01697     }
01698 
01704     protected function _sendMail()
01705     {
01706         return parent::send();
01707     }
01708 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5