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 
00283     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00284     {
00285         $myConfig = $this->getConfig();
00286 
00287         $sCustHTML  = $this->_sOrderUserTemplate;
00288         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00289 
00290         // add user defined stuff if there is any
00291         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00292 
00293         //set mail params (from, fromName, smtp)
00294         $oShop = $this->_getShop();
00295         $this->_setMailParams( $oShop );
00296 
00297         // P
00298         // setting some deprecated variables
00299         $oOrder->oDelSet = $oOrder->getDelSet();
00300 
00301         $oUser = $oOrder->getOrderUser();
00302         // create messages
00303         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00304         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00305         $oSmarty->assign( "order", $oOrder);
00306         $oSmarty->assign( "shop", $oShop );
00307         $oSmarty->assign( "oViewConf", $oShop );
00308         $oSmarty->assign( "user", $oUser );
00309         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00310         $oSmarty->assign( "basket", $oOrder->getBasket() );
00311         $oSmarty->assign( "payment", $oOrder->getPayment() );
00312         if ( $oUser ) {
00313             $oSmarty->assign( "reviewuser", $oUser->getReviewUserHash($oUser->getId()) );
00314         }
00315         $oSmarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00316 
00317         //deprecated vars
00318         $oSmarty->assign( "iswishlist", true);
00319         $oSmarty->assign( "isreview", true);
00320 
00321         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00322             $oSmarty->assign( "vouchers", $aVoucherList );
00323         }
00324 
00325         $oOutputProcessor = oxNew( "oxoutput" );
00326         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00327 
00328         foreach ( $aNewSmartyArray as $key => $val ) {
00329             $oSmarty->assign( $key, $val );
00330         }
00331 
00332         $this->setBody( $oSmarty->fetch( $sCustHTML) );
00333         $this->setAltBody( $oSmarty->fetch( $sCustPLAIN) );
00334 
00335         // #586A
00336         if ( $sSubject === null ) {
00337             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00338                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00339             } else {
00340                 $sSubject = $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")";
00341             }
00342         }
00343 
00344         $this->setSubject( $sSubject );
00345 
00346         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00347 
00348         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00349         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00350 
00351         $blSuccess = $this->send();
00352 
00353         return $blSuccess;
00354     }
00355 
00365     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00366     {
00367         $myConfig = $this->getConfig();
00368 
00369         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00370         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00371 
00372         // cleanup
00373         $this->_clearMailer();
00374 
00375         // add user defined stuff if there is any
00376         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00377 
00378         // send confirmation to shop owner
00379         $sFullName = $oOrder->getOrderUser()->oxuser__oxfname->value . " " . $oOrder->getOrderUser()->oxuser__oxlname->value;
00380         $this->setFrom( $oOrder->getOrderUser()->oxuser__oxusername->value, $sFullName );
00381 
00382         $oLang = oxLang::getInstance();
00383         $iOrderLang = $oLang->getTplLanguage();
00384 
00385         $oShop = $this->_getShop();
00386 
00387         // if running shop language is different from admin lang. set in config
00388         // we have to load shop in config language
00389         if ( $oShop->getLanguage() != $iOrderLang ) {
00390             $oShop = $this->_getShop( $iOrderLang );
00391         }
00392 
00393         $this->setSmtp( $oShop );
00394 
00395         // create messages
00396         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00397         $oSmarty->assign( "charset", $oLang->translateString("charset"));
00398         $oSmarty->assign( "order", $oOrder );
00399         $oSmarty->assign( "shop", $oShop );
00400         $oSmarty->assign( "oViewConf", $oShop );
00401         $oSmarty->assign( "user", $oOrder->getOrderUser() );
00402         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00403         $oSmarty->assign( "basket", $oOrder->getBasket() );
00404         $oSmarty->assign( "payment", $oOrder->getPayment() );
00405 
00406         //deprecated var
00407         $oSmarty->assign( "iswishlist", true);
00408 
00409         if( $oOrder->getVoucherList() )
00410             $oSmarty->assign( "vouchers", $oOrder->getVoucherList() );
00411 
00412         $oOutputProcessor = oxNew( "oxoutput" );
00413         $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
00414         foreach ($aNewSmartyArray as $key => $val)
00415             $oSmarty->assign( $key, $val );
00416 
00417         //path to admin message template file
00418         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00419 
00420         $this->setBody( $oSmarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00421         $this->setAltBody( $oSmarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00422 
00423         //Sets subject to email
00424         // #586A
00425         if ( $sSubject === null ) {
00426             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00427                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00428             } else {
00429                  $sSubject = $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")";
00430             }
00431         }
00432 
00433         $this->setSubject( $sSubject );
00434         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00435 
00436         if ( $oOrder->getOrderUser()->oxuser__oxusername->value != "admin" )
00437             $this->setReplyTo( $oOrder->getOrderUser()->oxuser__oxusername->value, $sFullName );
00438 
00439         $blSuccess = $this->send();
00440 
00441         // add user history
00442         $oRemark = oxNew( "oxremark" );
00443         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00444         $oRemark->oxremark__oxparentid  = new oxField($oOrder->getOrderUser()->getId(), oxField::T_RAW);
00445         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00446         $oRemark->save();
00447 
00448 
00449         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00450             exit();
00451         }
00452 
00453         return $blSuccess;
00454     }
00455 
00465     public function sendRegisterEmail( $oUser, $sSubject = null )
00466     {
00467         // add user defined stuff if there is any
00468         $oUser = $this->_addUserRegisterEmail( $oUser );
00469 
00470         // shop info
00471         $oShop = $this->_getShop();
00472 
00473         //set mail params (from, fromName, smtp )
00474         $this->_setMailParams( $oShop );
00475 
00476         // create messages
00477         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00478         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00479         $oSmarty->assign( "shop", $oShop );
00480         $oSmarty->assign( "oViewConf", $oShop );
00481         $oSmarty->assign( "user", $oUser );
00482 
00483         $oOutputProcessor = oxNew( "oxoutput" );
00484         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00485 
00486         foreach ( $aNewSmartyArray as $key => $val ) {
00487             $oSmarty->assign( $key, $val );
00488         }
00489 
00490         $this->setBody( $oSmarty->fetch( "email_register_html.tpl") );
00491         $this->setAltBody( $oSmarty->fetch( "email_register_plain.tpl") );
00492 
00493         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->value );
00494 
00495         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00496 
00497         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00498         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00499 
00500         return $this->send();
00501     }
00502 
00512     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00513     {
00514         $myConfig = $this->getConfig();
00515         $oDb = oxDb::getDb();
00516 
00517         // shop info
00518         $oShop = $this->_getShop();
00519 
00520         // add user defined stuff if there is any
00521         $oShop = $this->_addForgotPwdEmail( $oShop);
00522 
00523         //set mail params (from, fromName, smtp)
00524         $this->_setMailParams( $oShop );
00525 
00526         // user
00527         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00528         $sOrder = "";
00529         if (oxConfig::getInstance()->getConfigParam( 'blMallUsers' )) {
00530             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00531         } else {
00532             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00533         }
00534 
00535         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00536         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00537 
00538             $oUser = oxNew( 'oxuser' );
00539             if ( $oUser->load($sOxId) ) {
00540                 // create messages
00541                 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00542                 $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00543                 $oSmarty->assign( "shop", $oShop );
00544                 $oSmarty->assign( "oViewConf", $oShop );
00545                 $oSmarty->assign( "user", $oUser );
00546 
00547                 $oOutputProcessor = oxNew( "oxoutput" );
00548                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00549 
00550                 foreach ( $aNewSmartyArray as $key => $val ) {
00551                     $oSmarty->assign($key, $val);
00552                 }
00553 
00554                 $this->setBody( $oSmarty->fetch( "email_forgotpwd_html.tpl") );
00555                 $this->setAltBody( $oSmarty->fetch( "email_forgotpwd_plain.tpl") );
00556 
00557                 //sets subject of email
00558                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->value );
00559 
00560                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00561 
00562                 $this->setRecipient( $sEmailAddress, $sFullName );
00563                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00564 
00565                 return $this->send();
00566             }
00567         }
00568 
00569         return false;
00570     }
00571 
00582     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00583     {
00584 
00585         // shop info
00586         $oShop = $this->_getShop();
00587 
00588         //set mail params (from, fromName, smtp)
00589         $this->_setMailParams( $oShop );
00590 
00591         $this->setBody( $sMessage );
00592         $this->setSubject( $sSubject );
00593 
00594         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00595         $this->setFrom( $sEmailAddress, "" );
00596         $this->setReplyTo( $sEmailAddress, "" );
00597 
00598         return $this->send();
00599     }
00600 
00610     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00611     {
00612 
00613         // add user defined stuff if there is any
00614         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00615 
00616         // shop info
00617         $oShop = $this->_getShop();
00618 
00619         //set mail params (from, fromName, smtp)
00620         $this->_setMailParams( $oShop );
00621 
00622         // create messages
00623         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00624         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00625         $oSmarty->assign( "shop", $oShop );
00626         $oSmarty->assign( "oViewConf", $oShop );
00627         $oSmarty->assign( "user", $oUser );
00628 
00629         $oOutputProcessor = oxNew( "oxoutput" );
00630         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00631         foreach ( $aNewSmartyArray as $key => $val ) {
00632             $oSmarty->assign( $key, $val );
00633         }
00634 
00635         $this->setBody( $oSmarty->fetch("email_newsletteroptin_html.tpl") );
00636         $this->setAltBody( $oSmarty->fetch( "email_newsletteroptin_plain.tpl") );
00637         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00638 
00639         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00640 
00641         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00642         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00643         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00644 
00645         return $this->send();
00646     }
00647 
00658     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00659     {
00660         // shop info
00661         $oShop = $this->_getShop();
00662 
00663         //set mail params (from, fromName, smtp)
00664         $this->_setMailParams( $oShop );
00665 
00666         $sBody = $oNewsLetter->getHtmlText();
00667 
00668         if ( !empty($sBody) ) {
00669             $this->setBody( $sBody );
00670             $this->setAltBody( $oNewsLetter->getPlainText() );
00671         } else {
00672             $this->isHtml( false );
00673             $this->setBody( $oNewsLetter->getPlainText() );
00674         }
00675 
00676         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->value );
00677 
00678         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00679         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00680         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00681 
00682         return $this->send();
00683     }
00684 
00694     public function sendSuggestMail( $oParams, $oProduct )
00695     {
00696         $myConfig = $this->getConfig();
00697 
00698         //sets language of shop
00699         $iCurrLang = 0;
00700         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00701         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00702             $iCurrLang = $iActShopLang;
00703         }
00704 
00705         // shop info
00706         $oShop = $this->_getShop( $iCurrLang );
00707 
00708         //sets language to article
00709         if ( $oProduct->getLanguage() != $iCurrLang ) {
00710             $oProduct->setLanguage( $iCurrLang );
00711             $oProduct->load( $oProduct->getId() );
00712         }
00713 
00714         // mailer stuff
00715         $this->setFrom( $oParams->send_email, $oParams->send_name );
00716         $this->setSMTP();
00717 
00718         // create messages
00719         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00720         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00721         $oSmarty->assign( "shop", $oShop );
00722         $oSmarty->assign( "oViewConf", $oShop );
00723         $oSmarty->assign( "userinfo", $oParams );
00724         $oSmarty->assign( "product", $oProduct );
00725 
00726         $oOutputProcessor = oxNew( "oxoutput" );
00727         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00728 
00729         foreach ( $aNewSmartyArray as $key => $val ) {
00730             $oSmarty->assign( $key, $val );
00731         }
00732 
00733         $this->setBody( $oSmarty->fetch( "email_suggest_html.tpl") );
00734         $this->setAltBody( $oSmarty->fetch( "email_suggest_plain.tpl") );
00735         $this->setSubject( $oParams->send_subject );
00736 
00737         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00738         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00739 
00740         return $this->send();
00741     }
00742 
00752     public function sendSendedNowMail( $oOrder, $sSubject = null )
00753     {
00754         $myConfig = $this->getConfig();
00755 
00756         $iOrderLang = 0;
00757         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00758             $iOrderLang = $oOrder->oxorder__oxlang->value;
00759         }
00760 
00761         // shop info
00762         $oShop = $this->_getShop( $iOrderLang );
00763 
00764         //set mail params (from, fromName, smtp)
00765         $this->_setMailParams( $oShop );
00766 
00767         //override default wrap
00768         //$this->setMailWordWrap( 0 );
00769 
00770         //create messages
00771         $oLang = oxLang::getInstance();
00772         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00773         $oSmarty->assign( "charset", $oLang->translateString("charset"));
00774         $oSmarty->assign( "shop", $oShop );
00775         $oSmarty->assign( "oViewConf", $oShop );
00776         $oSmarty->assign( "order", $oOrder );
00777         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00778 
00779         //deprecated var
00780         $oSmarty->assign( "isreview", true);
00781         $oUser = oxNew( 'oxuser' );
00782         $oSmarty->assign( "reviewuser", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
00783 
00784         $oOutputProcessor = oxNew( "oxoutput" );
00785         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00786 
00787         foreach ( $aNewSmartyArray as $key => $val ) {
00788             $oSmarty->assign( $key, $val );
00789         }
00790 
00791         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00792         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
00793         //V send email in order language
00794         $iOldTplLang = $oLang->getTplLanguage();
00795         $iOldBaseLang = $oLang->getTplLanguage();
00796         $oLang->setTplLanguage( $iOrderLang );
00797         $oLang->setBaseLanguage( $iOrderLang );
00798 
00799         $oSmarty->security_settings['INCLUDE_ANY'] = true;
00800 
00801         //Sets path to template file
00802         $sPathToTemplate = $myConfig->getTemplateDir(false)."/";
00803 
00804         $this->setBody( $oSmarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00805         $this->setAltBody( $oSmarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00806         $oLang->setTplLanguage( $iOldTplLang );
00807         $oLang->setBaseLanguage( $iOldBaseLang );
00808         // set it back
00809         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00810 
00811         //Sets subject to email
00812         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->value );
00813 
00814         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00815 
00816         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00817         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00818         return $this->send();
00819     }
00820 
00835     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00836     {
00837 
00838         /* P
00839         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00840         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00841         */
00842 
00843         // shop info
00844         $oShop = $this->_getShop();
00845 
00846         //set mail params (from, fromName, smtp)
00847         $this->_setMailParams( $oShop );
00848 
00849         $this->setBody( $sMessage );
00850         $this->setSubject( $sSubject );
00851 
00852         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00853 
00854         if ( !$sEmailAddress ) {
00855             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00856         }
00857 
00858         $this->setFrom( $sEmailAddress, "" );
00859         $this->setReplyTo( $sEmailAddress, "" );
00860 
00861         //attaching files
00862         $blAttashSucc = true;
00863         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00864         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00865             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00866                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00867             } else {
00868                 $blAttashSucc = false;
00869                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00870             }
00871         }
00872 
00873         if ( !$blAttashSucc ) {
00874             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00875             $this->clearAttachments();
00876             return false;
00877         }
00878 
00879         $aStatus[] = 3;     //"Mailing backup files ...";
00880         $blSend = $this->send();
00881         $this->clearAttachments();
00882 
00883         return $blSend;
00884     }
00885 
00896     public function sendEmail( $sTo, $sSubject, $sBody )
00897     {
00898         //set mail params (from, fromName, smtp)
00899         $this->_setMailParams();
00900 
00901         if ( is_array($sTo) ) {
00902             foreach ($sTo as $sAddress) {
00903                 $this->setRecipient( $sAddress, "" );
00904                 $this->setReplyTo( $sAddress, "" );
00905             }
00906         } else {
00907             $this->setRecipient( $sTo, "" );
00908             $this->setReplyTo( $sTo, "" );
00909         }
00910 
00911         //may be changed later
00912         $this->isHtml( false );
00913 
00914         $this->setSubject( $sSubject );
00915         $this->setBody( $sBody );
00916 
00917         return $this->send();
00918     }
00919 
00928     public function sendStockReminder( $aBasketContents, $sSubject = null )
00929     {
00930         $blSend = false;
00931 
00932         $oArticleList = oxNew( "oxarticlelist" );
00933         $oArticleList->loadStockRemindProducts( $aBasketContents );
00934 
00935         // nothing to remind?
00936         if ( $oArticleList->count() ) {
00937             $oShop = $this->_getShop();
00938 
00939             //set mail params (from, fromName, smtp... )
00940             $this->_setMailParams( $oShop );
00941             $oLang = oxLang::getInstance();
00942 
00943             $oSmarty = oxUtilsView::getInstance()->getSmarty();
00944             $oSmarty->assign( "charset", $oLang->translateString( "charset" ) );
00945             $oSmarty->assign( "shop", $oShop );
00946             $oSmarty->assign( "oViewConf", $oShop );
00947             $oSmarty->assign( "articles", $oArticleList );
00948 
00949             //path to admin message template file
00950             $sPathToTemplate = $this->getConfig()->getTemplateDir( false ).'/';
00951 
00952             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00953             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00954             $this->setBody( $oSmarty->fetch( $sPathToTemplate . $this->_sReminderMailTemplate ) );
00955             $this->setAltBody( "" );
00956             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
00957 
00958             $blSend = $this->send();
00959         }
00960 
00961         return $blSend;
00962     }
00963 
00972     public function sendWishlistMail( $oParams )
00973     {
00974         $myConfig = $this->getConfig();
00975 
00976         $this->_clearMailer();
00977 
00978         // shop info
00979         $oShop = $this->_getShop();
00980 
00981         // mailer stuff
00982         $this->setFrom( $oParams->send_email, $oParams->send_name );
00983         $this->setSMTP();
00984 
00985         // create messages
00986         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00987         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00988         $oSmarty->assign( "shop", $oShop );
00989         $oSmarty->assign( "oViewConf", $oShop );
00990         $oSmarty->assign( "userinfo", $oParams );
00991 
00992         $this->setBody( $oSmarty->fetch( "email_wishlist_html.tpl") );
00993         $this->setAltBody( $oSmarty->fetch( "email_wishlist_plain.tpl") );
00994         $this->setSubject( $oParams->send_subject );
00995 
00996         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00997         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00998 
00999         return $this->send();
01000     }
01001 
01012     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01013     {
01014         $this->_clearMailer();
01015         $oShop = $this->_getShop();
01016 
01017         //set mail params (from, fromName, smtp)
01018         $this->_setMailParams( $oShop );
01019 
01020         $iAlarmLang = $oShop->getLanguage();
01021 
01022         $oArticle = oxNew( "oxarticle" );
01023         $oArticle->setSkipAbPrice( true );
01024         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01025 
01026         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01027         $oLang = oxLang::getInstance();
01028 
01029         // create messages
01030         $oSmarty = oxUtilsView::getInstance()->getSmarty();
01031         $oSmarty->assign( "shop", $oShop );
01032         $oSmarty->assign( "oViewConf", $oShop );
01033         $oSmarty->assign( "product", $oArticle );
01034         $oSmarty->assign( "email", $aParams['email']);
01035         $oSmarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01036         $oSmarty->assign( "currency", $oCur );
01037 
01038         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01039         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value );
01040         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01041         $this->setFrom( $aParams['email'], "" );
01042         $this->setReplyTo( $aParams['email'], "" );
01043 
01044         return $this->send();
01045     }
01046 
01058     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01059     {
01060         $sBody = $this->getBody();
01061         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01062 
01063             $oFileUtils = oxUtilsFile::getInstance();
01064             $blReSetBody = false;
01065 
01066             // preparing imput
01067             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01068             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01069             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01070 
01071             if (is_array($matches) && count($matches)) {
01072                 $aImageCache = array();
01073                 $myUtils = oxUtils::getInstance();
01074                 $myUtilsObject = oxUtilsObject::getInstance();
01075 
01076                 foreach ($matches as $aImage) {
01077 
01078                     $image = $aImage[1];
01079                     $sFileName = '';
01080                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01081                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01082                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01083                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01084                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01085                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01086                     }
01087 
01088                     if ($sFileName && @is_file($sFileName)) {
01089                         $sCId = '';
01090                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01091                             $sCId = $aImageCache[$sFileName];
01092                         } else {
01093                             $sCId = $myUtilsObject->generateUID();
01094                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01095                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01096                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01097                                     $aImageCache[$sFileName] = $sCId;
01098                                 } else {
01099                                     $sCId = '';
01100                                 }
01101                             }
01102                         }
01103                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01104                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01105                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01106                                 $blReSetBody = true;
01107                             }
01108                         }
01109                     }
01110                 }
01111             }
01112 
01113             if ( $blReSetBody ) {
01114                 $this->setBody( $sBody );
01115             }
01116         }
01117     }
01118 
01126     public function setSubject( $sSubject = null )
01127     {
01128         // A. HTML entites in subjects must be replaced
01129         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01130         $this->Subject = $sSubject;
01131     }
01132 
01138     public function getSubject()
01139     {
01140         return $this->Subject;
01141     }
01142 
01152     public function setBody( $sBody = null, $blClearSid = true )
01153     {
01154         if ( $blClearSid ) {
01155             $sBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01156         }
01157 
01158         $this->Body = $sBody;
01159     }
01160 
01166     public function getBody()
01167     {
01168         return $this->Body;
01169     }
01170 
01180     public function setAltBody( $sAltBody = null, $blClearSid = true )
01181     {
01182         if ( $blClearSid ) {
01183             $sAltBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01184         }
01185 
01186         // A. alt body is used for plain text emails so we should eliminate HTML entities
01187         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01188         $this->AltBody = $sAltBody;
01189     }
01190 
01196     public function getAltBody()
01197     {
01198         return $this->AltBody;
01199     }
01200 
01209     public function setRecipient( $sAddress = null, $sName = null )
01210     {
01211         // copying values as original class does not allow to access recipients array
01212         $this->_aRecipients[] = array( $sAddress, $sName );
01213 
01214         parent::AddAddress($sAddress, $sName );
01215     }
01216 
01224     public function getRecipient()
01225     {
01226         return $this->_aRecipients;
01227     }
01228 
01235     public function clearAllRecipients()
01236     {
01237         $this->_aRecipients = array();
01238         parent::clearAllRecipients();
01239     }
01240 
01252     public function setReplyTo( $sEmail = null, $sName = null )
01253     {
01254         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01255             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01256         }
01257 
01258         $this->_aReplies[] = array( $sEmail, $sName );
01259         parent::AddReplyTo( $sEmail, $sName );
01260     }
01261 
01267     public function getReplyTo()
01268     {
01269         return $this->_aReplies;
01270     }
01271 
01277     public function clearReplyTos()
01278     {
01279         $this->_aReplies = array();
01280         parent::clearReplyTos();
01281     }
01282 
01291     public function setFrom( $sFromAdress = null, $sFromName = null )
01292     {
01293         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01294         // this is simple but must work
01295         // dodger Task #1532 field "From" in emails from shops
01296         $this->From     = substr($sFromAdress, 0, 150);
01297         $this->FromName = substr($sFromName, 0, 150);
01298     }
01299 
01305     public function getFrom()
01306     {
01307         return $this->From;
01308     }
01309 
01315     public function getFromName()
01316     {
01317         return $this->FromName;
01318     }
01319 
01328     public function setCharSet( $sCharSet = null )
01329     {
01330         if ( !empty($sCharSet) ) {
01331             $this->CharSet = $sCharSet;
01332         } else {
01333             $this->CharSet = oxLang::getInstance()->translateString("charset");
01334         }
01335     }
01336 
01342     public function getCharSet()
01343     {
01344         return $this->CharSet;
01345     }
01346 
01354     public function setMailer( $sMailer = null )
01355     {
01356         $this->Mailer = $sMailer;
01357     }
01358 
01364     public function getMailer()
01365     {
01366         return $this->Mailer;
01367     }
01368 
01376     public function setHost( $sHost = null )
01377     {
01378         $this->Host = $sHost;
01379     }
01380 
01386     public function getErrorInfo()
01387     {
01388         return $this->ErrorInfo;
01389     }
01390 
01399     public function setMailWordWrap( $iWordWrap = null )
01400     {
01401         $this->WordWrap = $iWordWrap;
01402     }
01403 
01411     public function setUseInlineImages( $blUseImages = null )
01412     {
01413         $this->_blInlineImgEmail = $blUseImages;
01414     }
01415 
01426     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01427     {
01428         $sFullPath = $sAttPath . $sAttFile;
01429 
01430         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01431         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01432     }
01433 
01445     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01446     {
01447         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01448         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01449     }
01450 
01456     public function getAttachments()
01457     {
01458         return $this->_aAttachments;
01459     }
01460 
01466     public function clearAttachments()
01467     {
01468         $this->_aAttachments = array();
01469         return parent::ClearAttachments();
01470     }
01471 
01481     public function headerLine($sName, $sValue)
01482     {
01483         if (stripos($sName, 'X-') !== false) {
01484             return;
01485         }
01486         return parent::headerLine($sName, $sValue);
01487     }
01488 
01494     protected function _getUseInlineImages()
01495     {
01496         return $this->_blInlineImgEmail;
01497     }
01498 
01504     protected function _sendMailErrorMsg()
01505     {
01506         // build addresses
01507         $sToAdress  = "";
01508         $sToName    = "";
01509 
01510         $aRecipients = $this->getRecipient();
01511 
01512         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01513 
01514         foreach ( $aRecipients as $aEMail ) {
01515             $sOwnerMessage .= $aEMail[0];
01516             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01517             $sOwnerMessage .= " \n ";
01518         }
01519         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01520 
01521         // shop info
01522         $oShop = $this->_getShop();
01523 
01524         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01525 
01526         return $blRet;
01527     }
01528 
01538     protected function _addUserInfoOrderEMail( $oOrder )
01539     {
01540         return $oOrder;
01541     }
01542 
01552     protected function _addUserRegisterEmail( $oUser )
01553     {
01554         return $oUser;
01555     }
01556 
01566     protected function _addForgotPwdEmail( $oShop )
01567     {
01568         return $oShop;
01569     }
01570 
01580     protected function _addNewsletterDbOptInMail( $oUser )
01581     {
01582         return $oUser;
01583     }
01584 
01590     protected function _clearMailer()
01591     {
01592         $this->clearAllRecipients();
01593         $this->clearReplyTos();
01594         $this->clearAttachments();
01595 
01596         //workaround for phpmailer as it doesn't cleanup as it should
01597         $this->error_count = 0;
01598         $this->ErrorInfo   = '';
01599     }
01600 
01608     protected function _setMailParams( $oShop = null )
01609     {
01610         $this->_clearMailer();
01611 
01612         if ( !$oShop ) {
01613             $oShop = $this->_getShop();
01614         }
01615 
01616         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01617         $this->setSmtp( $oShop );
01618     }
01619 
01628     protected function _getShop( $iLangId = null )
01629     {
01630         $myConfig = $this->getConfig();
01631         if ( !isset($iLangId) ) {
01632             $iLangId = 0;
01633             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01634             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01635                 $iLangId = $iActShopLang;
01636             }
01637         }
01638         if ( isset($this->_oShop) && $this->_oShop ) {
01639             // if oShop already setted and reqesting oShop with same language as current oShop,
01640             // or wihtout lang param, return oShop object
01641             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01642                 return $this->_oShop;
01643             }
01644         }
01645 
01646         $this->_oShop = oxNew( 'oxshop' );
01647 
01648         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01649 
01650         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01651 
01652         $oView = $myConfig->getActiveView();
01653         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01654 
01655         return $this->_oShop;
01656     }
01657 
01666     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01667     {
01668         $this->SMTPAuth = true;
01669         $this->Username = $sUserName;
01670         $this->Password = $sUserPassword;
01671     }
01672 
01680     protected function _setSmtpDebug( $blDebug = null )
01681     {
01682         $this->SMTPDebug = $blDebug;
01683     }
01684 
01690     protected function _setMailerPluginDir()
01691     {
01692         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01693     }
01694 
01701     protected function _makeOutputProcessing()
01702     {
01703         $oOutput = oxNew( "oxoutput" );
01704         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01705         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01706         $oOutput->processEmail( $this );
01707     }
01708 
01714     protected function _sendMail()
01715     {
01716         return parent::send();
01717     }
01718 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5