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         $smarty = oxUtilsView::getInstance()->getSmarty();
00304         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00305         $smarty->assign( "order", $oOrder);
00306         $smarty->assign( "shop", $oShop );
00307         $smarty->assign( "oViewConf", $oShop );
00308         $smarty->assign( "user", $oUser );
00309         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00310         $smarty->assign( "basket", $oOrder->getBasket() );
00311         $smarty->assign( "payment", $oOrder->getPayment() );
00312         if ( $oUser ) {
00313             $smarty->assign( "reviewuser", $oUser->getReviewUserHash($oUser->getId()) );
00314         }
00315         $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00316 
00317         //deprecated vars
00318         $smarty->assign( "iswishlist", true);
00319         $smarty->assign( "isreview", true);
00320 
00321         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00322             $smarty->assign( "vouchers", $aVoucherList );
00323         }
00324 
00325         $oOutputProcessor = oxNew( "oxoutput" );
00326         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00327 
00328         foreach ( $aNewSmartyArray as $key => $val ) {
00329             $smarty->assign( $key, $val );
00330         }
00331 
00332         $this->setBody( $smarty->fetch( $sCustHTML) );
00333         $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00334 
00335         // #586A
00336         if ( $sSubject === null ) {
00337             if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00338                 $sSubject = $smarty->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         $smarty = oxUtilsView::getInstance()->getSmarty();
00397         $smarty->assign( "charset", $oLang->translateString("charset"));
00398         $smarty->assign( "order", $oOrder );
00399         $smarty->assign( "shop", $oShop );
00400         $smarty->assign( "oViewConf", $oShop );
00401         $smarty->assign( "user", $oOrder->getOrderUser() );
00402         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00403         $smarty->assign( "basket", $oOrder->getBasket() );
00404         $smarty->assign( "payment", $oOrder->getPayment() );
00405 
00406         //deprecated var
00407         $smarty->assign( "iswishlist", true);
00408 
00409         if( $oOrder->getVoucherList() )
00410             $smarty->assign( "vouchers", $oOrder->getVoucherList() );
00411 
00412         $oOutputProcessor = oxNew( "oxoutput" );
00413         $aNewSmartyArray = $oOutputProcessor->processViewArray($smarty->get_template_vars(), "oxemail");
00414         foreach ($aNewSmartyArray as $key => $val)
00415             $smarty->assign( $key, $val );
00416 
00417         //path to admin message template file
00418         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00419 
00420         $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00421         $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00422 
00423         //Sets subject to email
00424         // #586A
00425         if ( $sSubject === null ) {
00426             if ( $smarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00427                 $sSubject = $smarty->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         $smarty = oxUtilsView::getInstance()->getSmarty();
00478         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00479         $smarty->assign( "shop", $oShop );
00480         $smarty->assign( "oViewConf", $oShop );
00481         $smarty->assign( "user", $oUser );
00482 
00483         $oOutputProcessor = oxNew( "oxoutput" );
00484         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00485 
00486         foreach ( $aNewSmartyArray as $key => $val ) {
00487             $smarty->assign( $key, $val );
00488         }
00489 
00490         $this->setBody( $smarty->fetch( "email_register_html.tpl") );
00491         $this->setAltBody( $smarty->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 
00516         // shop info
00517         $oShop = $this->_getShop();
00518 
00519         // add user defined stuff if there is any
00520         $oShop = $this->_addForgotPwdEmail( $oShop);
00521 
00522         //set mail params (from, fromName, smtp)
00523         $this->_setMailParams( $oShop );
00524 
00525         // user
00526         $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and
00527                     oxuser.oxusername = '$sEmailAddress' and oxuser.oxpassword != ''
00528                     order by oxshopid = '".$oShop->getId()."' desc";
00529 
00530         if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00531 
00532             $oUser = oxNew( 'oxuser' );
00533             if ( $oUser->load($sOxId) ) {
00534                 // create messages
00535                 $smarty = oxUtilsView::getInstance()->getSmarty();
00536                 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00537                 $smarty->assign( "shop", $oShop );
00538                 $smarty->assign( "oViewConf", $oShop );
00539                 $smarty->assign( "user", $oUser );
00540 
00541                 $oOutputProcessor = oxNew( "oxoutput" );
00542                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00543 
00544                 foreach ( $aNewSmartyArray as $key => $val ) {
00545                     $smarty->assign($key, $val);
00546                 }
00547 
00548                 $this->setBody( $smarty->fetch( "email_forgotpwd_html.tpl") );
00549                 $this->setAltBody( $smarty->fetch( "email_forgotpwd_plain.tpl") );
00550 
00551                 //sets subject of email
00552                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->value );
00553 
00554                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00555 
00556                 $this->setRecipient( $sEmailAddress, $sFullName );
00557                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00558 
00559                 return $this->send();
00560             }
00561         }
00562 
00563         return false;
00564     }
00565 
00576     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00577     {
00578 
00579         // shop info
00580         $oShop = $this->_getShop();
00581 
00582         //set mail params (from, fromName, smtp)
00583         $this->_setMailParams( $oShop );
00584 
00585         $this->setBody( $sMessage );
00586         $this->setSubject( $sSubject );
00587 
00588         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00589         $this->setFrom( $sEmailAddress, "" );
00590         $this->setReplyTo( $sEmailAddress, "" );
00591 
00592         return $this->send();
00593     }
00594 
00604     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00605     {
00606 
00607         // add user defined stuff if there is any
00608         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00609 
00610         // shop info
00611         $oShop = $this->_getShop();
00612 
00613         //set mail params (from, fromName, smtp)
00614         $this->_setMailParams( $oShop );
00615 
00616         // create messages
00617         $smarty = oxUtilsView::getInstance()->getSmarty();
00618         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00619         $smarty->assign( "shop", $oShop );
00620         $smarty->assign( "oViewConf", $oShop );
00621         $smarty->assign( "user", $oUser );
00622 
00623         $oOutputProcessor = oxNew( "oxoutput" );
00624         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00625         foreach ( $aNewSmartyArray as $key => $val ) {
00626             $smarty->assign( $key, $val );
00627         }
00628 
00629         $this->setBody( $smarty->fetch("email_newsletteroptin_html.tpl") );
00630         $this->setAltBody( $smarty->fetch( "email_newsletteroptin_plain.tpl") );
00631         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00632 
00633         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00634 
00635         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00636         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00637         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00638 
00639         return $this->send();
00640     }
00641 
00652     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00653     {
00654         // shop info
00655         $oShop = $this->_getShop();
00656 
00657         //set mail params (from, fromName, smtp)
00658         $this->_setMailParams( $oShop );
00659 
00660         $sBody = $oNewsLetter->getHtmlText();
00661 
00662         if ( !empty($sBody) ) {
00663             $this->setBody( $sBody );
00664             $this->setAltBody( $oNewsLetter->getPlainText() );
00665         } else {
00666             $this->isHtml( false );
00667             $this->setBody( $oNewsLetter->getPlainText() );
00668         }
00669 
00670         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->value );
00671 
00672         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00673         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00674         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00675 
00676         return $this->send();
00677     }
00678 
00688     public function sendSuggestMail( $oParams, $oProduct )
00689     {
00690         $myConfig = $this->getConfig();
00691 
00692         //sets language of shop
00693         $iCurrLang = 0;
00694         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00695         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00696             $iCurrLang = $iActShopLang;
00697         }
00698 
00699         // shop info
00700         $oShop = $this->_getShop( $iCurrLang );
00701 
00702         //sets language to article
00703         if ( $oProduct->getLanguage() != $iCurrLang ) {
00704             $oProduct->setLanguage( $iCurrLang );
00705             $oProduct->load( $oProduct->getId() );
00706         }
00707 
00708         // mailer stuff
00709         $this->setFrom( $oParams->send_email, $oParams->send_name );
00710         $this->setSMTP();
00711 
00712         // create messages
00713         $smarty = oxUtilsView::getInstance()->getSmarty();
00714         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00715         $smarty->assign( "shop", $oShop );
00716         $smarty->assign( "oViewConf", $oShop );
00717         $smarty->assign( "userinfo", $oParams );
00718         $smarty->assign( "product", $oProduct );
00719 
00720         $oOutputProcessor = oxNew( "oxoutput" );
00721         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00722 
00723         foreach ( $aNewSmartyArray as $key => $val ) {
00724             $smarty->assign( $key, $val );
00725         }
00726 
00727         $this->setBody( $smarty->fetch( "email_suggest_html.tpl") );
00728         $this->setAltBody( $smarty->fetch( "email_suggest_plain.tpl") );
00729         $this->setSubject( $oParams->send_subject );
00730 
00731         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00732         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00733 
00734         return $this->send();
00735     }
00736 
00746     public function sendSendedNowMail( $oOrder, $sSubject = null )
00747     {
00748         $myConfig = $this->getConfig();
00749 
00750         $iOrderLang = 0;
00751         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00752             $iOrderLang = $oOrder->oxorder__oxlang->value;
00753         }
00754 
00755         // shop info
00756         $oShop = $this->_getShop( $iOrderLang );
00757 
00758         //set mail params (from, fromName, smtp)
00759         $this->_setMailParams( $oShop );
00760 
00761         //override default wrap
00762         //$this->setMailWordWrap( 0 );
00763 
00764         //create messages
00765         $oLang = oxLang::getInstance();
00766         $smarty = oxUtilsView::getInstance()->getSmarty();
00767         $smarty->assign( "charset", $oLang->translateString("charset"));
00768         $smarty->assign( "shop", $oShop );
00769         $smarty->assign( "oViewConf", $oShop );
00770         $smarty->assign( "order", $oOrder );
00771         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00772 
00773         //deprecated var
00774         $smarty->assign( "isreview", true);
00775         $oUser = oxNew( 'oxuser' );
00776         $smarty->assign( "reviewuser", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
00777 
00778         $oOutputProcessor = oxNew( "oxoutput" );
00779         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00780 
00781         foreach ( $aNewSmartyArray as $key => $val ) {
00782             $smarty->assign( $key, $val );
00783         }
00784 
00785         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00786         $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00787         //V send email in order language
00788         $iOldTplLang = $oLang->getTplLanguage();
00789         $iOldBaseLang = $oLang->getTplLanguage();
00790         $oLang->setTplLanguage( $iOrderLang );
00791         $oLang->setBaseLanguage( $iOrderLang );
00792 
00793         $smarty->security_settings['INCLUDE_ANY'] = true;
00794 
00795         //Sets path to template file
00796         $sPathToTemplate = $myConfig->getTemplateDir(false)."/";
00797 
00798         $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00799         $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00800         $oLang->setTplLanguage( $iOldTplLang );
00801         $oLang->setBaseLanguage( $iOldBaseLang );
00802         // set it back
00803         $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00804 
00805         //Sets subject to email
00806         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->value );
00807 
00808         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00809 
00810         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00811         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00812         return $this->send();
00813     }
00814 
00829     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00830     {
00831 
00832         /* P
00833         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00834         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00835         */
00836 
00837         // shop info
00838         $oShop = $this->_getShop();
00839 
00840         //set mail params (from, fromName, smtp)
00841         $this->_setMailParams( $oShop );
00842 
00843         $this->setBody( $sMessage );
00844         $this->setSubject( $sSubject );
00845 
00846         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00847 
00848         if ( !$sEmailAddress ) {
00849             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00850         }
00851 
00852         $this->setFrom( $sEmailAddress, "" );
00853         $this->setReplyTo( $sEmailAddress, "" );
00854 
00855         //attaching files
00856         $blAttashSucc = true;
00857         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00858         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00859             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00860                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00861             } else {
00862                 $blAttashSucc = false;
00863                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00864             }
00865         }
00866 
00867         if ( !$blAttashSucc ) {
00868             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00869             $this->clearAttachments();
00870             return false;
00871         }
00872 
00873         $aStatus[] = 3;     //"Mailing backup files ...";
00874         $blSend = $this->send();
00875         $this->clearAttachments();
00876 
00877         return $blSend;
00878     }
00879 
00890     public function sendEmail( $sTo, $sSubject, $sBody )
00891     {
00892         //set mail params (from, fromName, smtp)
00893         $this->_setMailParams();
00894 
00895         if ( is_array($sTo) ) {
00896             foreach ($sTo as $sAddress) {
00897                 $this->setRecipient( $sAddress, "" );
00898                 $this->setReplyTo( $sAddress, "" );
00899             }
00900         } else {
00901             $this->setRecipient( $sTo, "" );
00902             $this->setReplyTo( $sTo, "" );
00903         }
00904 
00905         //may be changed later
00906         $this->isHtml( false );
00907 
00908         $this->setSubject( $sSubject );
00909         $this->setBody( $sBody );
00910 
00911         return $this->send();
00912     }
00913 
00922     public function sendStockReminder( $aBasketContents, $sSubject = null )
00923     {
00924         $myConfig = $this->getConfig();
00925 
00926         $aRemindArticles = array();
00927         foreach ( $aBasketContents as $oBasketItem ) {
00928             $oArticle = $oBasketItem->getArticle();
00929              // reminder not set
00930             if ( !$oArticle->oxarticles__oxremindactive->value || $oArticle->oxarticles__oxremindactive->value > 1 ) {
00931                 continue;
00932             }
00933 
00934             // number or articles available is more
00935             if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00936                 continue;
00937             }
00938 
00939             $aRemindArticles[] = $oArticle;
00940             $oArticle->disableReminder();
00941         }
00942 
00943         // nothing to remind ...
00944         if ( !count( $aRemindArticles ) ) {
00945             return false;
00946         }
00947         $oShop = $this->_getShop();
00948 
00949         //set mail params (from, fromName, smtp... )
00950         $this->_setMailParams( $oShop );
00951         $oLang = oxLang::getInstance();
00952 
00953 
00954         $smarty = oxUtilsView::getInstance()->getSmarty();
00955         $smarty->assign( "charset", $oLang->translateString("charset"));
00956         $smarty->assign( "shop", $oShop );
00957         $smarty->assign( "oViewConf", $oShop );
00958         $smarty->assign( "articles", $aRemindArticles );
00959 
00960         //path to admin message template file
00961         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00962 
00963         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00964         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00965         $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00966         $this->setAltBody( "" );
00967         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00968 
00969         return $this->send();
00970     }
00971 
00980     public function sendWishlistMail( $oParams )
00981     {
00982         $myConfig = $this->getConfig();
00983 
00984         $this->_clearMailer();
00985 
00986         // shop info
00987         $oShop = $this->_getShop();
00988 
00989         // mailer stuff
00990         $this->setFrom( $oParams->send_email, $oParams->send_name );
00991         $this->setSMTP();
00992 
00993         // create messages
00994         $smarty = oxUtilsView::getInstance()->getSmarty();
00995         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00996         $smarty->assign( "shop", $oShop );
00997         $smarty->assign( "oViewConf", $oShop );
00998         $smarty->assign( "userinfo", $oParams );
00999 
01000         $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
01001         $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
01002         $this->setSubject( $oParams->send_subject );
01003 
01004         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01005         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01006 
01007         return $this->send();
01008     }
01009 
01020     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01021     {
01022         $this->_clearMailer();
01023         $oShop = $this->_getShop();
01024 
01025         //set mail params (from, fromName, smtp)
01026         $this->_setMailParams( $oShop );
01027 
01028         $iAlarmLang = $oShop->getLanguage();
01029 
01030         $oArticle = oxNew( "oxarticle" );
01031         $oArticle->setSkipAbPrice( true );
01032         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01033 
01034         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01035         $oLang = oxLang::getInstance();
01036 
01037         // create messages
01038         $smarty = oxUtilsView::getInstance()->getSmarty();
01039         $smarty->assign( "shop", $oShop );
01040         $smarty->assign( "oViewConf", $oShop );
01041         $smarty->assign( "product", $oArticle );
01042         $smarty->assign( "email", $aParams['email']);
01043         $smarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01044         $smarty->assign( "currency", $oCur );
01045 
01046         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01047         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value );
01048         $this->setBody( $smarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01049         $this->setFrom( $aParams['email'], "" );
01050         $this->setReplyTo( $aParams['email'], "" );
01051 
01052         return $this->send();
01053     }
01054 
01066     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01067     {
01068         $sBody = $this->getBody();
01069         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01070 
01071             $oFileUtils = oxUtilsFile::getInstance();
01072             $blReSetBody = false;
01073 
01074             // preparing imput
01075             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01076             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01077             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01078 
01079             if (is_array($matches) && count($matches)) {
01080                 $aImageCache = array();
01081                 $myUtils = oxUtils::getInstance();
01082                 $myUtilsObject = oxUtilsObject::getInstance();
01083 
01084                 foreach ($matches as $aImage) {
01085 
01086                     $image = $aImage[1];
01087                     $sFileName = '';
01088                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01089                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01090                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01091                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01092                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01093                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01094                     }
01095 
01096                     if ($sFileName && @is_file($sFileName)) {
01097                         $sCId = '';
01098                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01099                             $sCId = $aImageCache[$sFileName];
01100                         } else {
01101                             $sCId = $myUtilsObject->generateUID();
01102                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01103                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01104                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01105                                     $aImageCache[$sFileName] = $sCId;
01106                                 } else {
01107                                     $sCId = '';
01108                                 }
01109                             }
01110                         }
01111                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01112                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01113                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01114                                 $blReSetBody = true;
01115                             }
01116                         }
01117                     }
01118                 }
01119             }
01120 
01121             if ( $blReSetBody ) {
01122                 $this->setBody( $sBody );
01123             }
01124         }
01125     }
01126 
01134     public function setSubject( $sSubject = null )
01135     {
01136         // A. HTML entites in subjects must be replaced
01137         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01138         $this->Subject = $sSubject;
01139     }
01140 
01146     public function getSubject()
01147     {
01148         return $this->Subject;
01149     }
01150 
01160     public function setBody( $sBody = null, $blClearSid = true )
01161     {
01162         if ( $blClearSid ) {
01163             $sBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01164         }
01165 
01166         $this->Body = $sBody;
01167     }
01168 
01174     public function getBody()
01175     {
01176         return $this->Body;
01177     }
01178 
01188     public function setAltBody( $sAltBody = null, $blClearSid = true )
01189     {
01190         if ( $blClearSid ) {
01191             $sAltBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01192         }
01193 
01194         // A. alt body is used for plain text emails so we should eliminate HTML entities
01195         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01196         $this->AltBody = $sAltBody;
01197     }
01198 
01204     public function getAltBody()
01205     {
01206         return $this->AltBody;
01207     }
01208 
01217     public function setRecipient( $sAddress = null, $sName = null )
01218     {
01219         // copying values as original class does not allow to access recipients array
01220         $this->_aRecipients[] = array( $sAddress, $sName );
01221 
01222         parent::AddAddress($sAddress, $sName );
01223     }
01224 
01232     public function getRecipient()
01233     {
01234         return $this->_aRecipients;
01235     }
01236 
01243     public function clearAllRecipients()
01244     {
01245         $this->_aRecipients = array();
01246         parent::clearAllRecipients();
01247     }
01248 
01260     public function setReplyTo( $sEmail = null, $sName = null )
01261     {
01262         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01263             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01264         }
01265 
01266         $this->_aReplies[] = array( $sEmail, $sName );
01267         parent::AddReplyTo( $sEmail, $sName );
01268     }
01269 
01275     public function getReplyTo()
01276     {
01277         return $this->_aReplies;
01278     }
01279 
01285     public function clearReplyTos()
01286     {
01287         $this->_aReplies = array();
01288         parent::clearReplyTos();
01289     }
01290 
01299     public function setFrom( $sFromAdress = null, $sFromName = null )
01300     {
01301         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01302         // this is simple but must work
01303         // dodger Task #1532 field "From" in emails from shops
01304         $this->From     = substr($sFromAdress, 0, 150);
01305         $this->FromName = substr($sFromName, 0, 150);
01306     }
01307 
01313     public function getFrom()
01314     {
01315         return $this->From;
01316     }
01317 
01323     public function getFromName()
01324     {
01325         return $this->FromName;
01326     }
01327 
01336     public function setCharSet( $sCharSet = null )
01337     {
01338         if ( !empty($sCharSet) ) {
01339             $this->CharSet = $sCharSet;
01340         } else {
01341             $this->CharSet = oxLang::getInstance()->translateString("charset");
01342         }
01343     }
01344 
01350     public function getCharSet()
01351     {
01352         return $this->CharSet;
01353     }
01354 
01362     public function setMailer( $sMailer = null )
01363     {
01364         $this->Mailer = $sMailer;
01365     }
01366 
01372     public function getMailer()
01373     {
01374         return $this->Mailer;
01375     }
01376 
01384     public function setHost( $sHost = null )
01385     {
01386         $this->Host = $sHost;
01387     }
01388 
01394     public function getErrorInfo()
01395     {
01396         return $this->ErrorInfo;
01397     }
01398 
01407     public function setMailWordWrap( $iWordWrap = null )
01408     {
01409         $this->WordWrap = $iWordWrap;
01410     }
01411 
01419     public function setUseInlineImages( $blUseImages = null )
01420     {
01421         $this->_blInlineImgEmail = $blUseImages;
01422     }
01423 
01434     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01435     {
01436         $sFullPath = $sAttPath . $sAttFile;
01437 
01438         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01439         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01440     }
01441 
01453     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01454     {
01455         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01456         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01457     }
01458 
01464     public function getAttachments()
01465     {
01466         return $this->_aAttachments;
01467     }
01468 
01474     public function clearAttachments()
01475     {
01476         $this->_aAttachments = array();
01477         return parent::ClearAttachments();
01478     }
01479 
01489     public function headerLine($sName, $sValue)
01490     {
01491         if (stripos($sName, 'X-') !== false) {
01492             return;
01493         }
01494         return parent::headerLine($sName, $sValue);
01495     }
01496 
01502     protected function _getUseInlineImages()
01503     {
01504         return $this->_blInlineImgEmail;
01505     }
01506 
01512     protected function _sendMailErrorMsg()
01513     {
01514         // build addresses
01515         $sToAdress  = "";
01516         $sToName    = "";
01517 
01518         $aRecipients = $this->getRecipient();
01519 
01520         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01521 
01522         foreach ( $aRecipients as $aEMail ) {
01523             $sOwnerMessage .= $aEMail[0];
01524             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01525             $sOwnerMessage .= " \n ";
01526         }
01527         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01528 
01529         // shop info
01530         $oShop = $this->_getShop();
01531 
01532         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01533 
01534         return $blRet;
01535     }
01536 
01546     protected function _addUserInfoOrderEMail( $oOrder )
01547     {
01548         return $oOrder;
01549     }
01550 
01560     protected function _addUserRegisterEmail( $oUser )
01561     {
01562         return $oUser;
01563     }
01564 
01574     protected function _addForgotPwdEmail( $oShop )
01575     {
01576         return $oShop;
01577     }
01578 
01588     protected function _addNewsletterDbOptInMail( $oUser )
01589     {
01590         return $oUser;
01591     }
01592 
01598     protected function _clearMailer()
01599     {
01600         $this->clearAllRecipients();
01601         $this->clearReplyTos();
01602         $this->clearAttachments();
01603 
01604         //workaround for phpmailer as it doesn't cleanup as it should
01605         $this->error_count = 0;
01606         $this->ErrorInfo   = '';
01607     }
01608 
01616     protected function _setMailParams( $oShop = null )
01617     {
01618         $this->_clearMailer();
01619 
01620         if ( !$oShop ) {
01621             $oShop = $this->_getShop();
01622         }
01623 
01624         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01625         $this->setSmtp( $oShop );
01626     }
01627 
01636     protected function _getShop( $iLangId = null )
01637     {
01638         $myConfig = $this->getConfig();
01639         if ( !isset($iLangId) ) {
01640             $iLangId = 0;
01641             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01642             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01643                 $iLangId = $iActShopLang;
01644             }
01645         }
01646         if ( isset($this->_oShop) && $this->_oShop ) {
01647             // if oShop already setted and reqesting oShop with same language as current oShop,
01648             // or wihtout lang param, return oShop object
01649             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01650                 return $this->_oShop;
01651             }
01652         }
01653 
01654         $this->_oShop = oxNew( 'oxshop' );
01655 
01656         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01657 
01658         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01659 
01660         $oView = $myConfig->getActiveView();
01661         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01662 
01663         return $this->_oShop;
01664     }
01665 
01674     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01675     {
01676         $this->SMTPAuth = true;
01677         $this->Username = $sUserName;
01678         $this->Password = $sUserPassword;
01679     }
01680 
01688     protected function _setSmtpDebug( $blDebug = null )
01689     {
01690         $this->SMTPDebug = $blDebug;
01691     }
01692 
01698     protected function _setMailerPluginDir()
01699     {
01700         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01701     }
01702 
01709     protected function _makeOutputProcessing()
01710     {
01711         $oOutput = oxNew( "oxoutput" );
01712         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01713         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01714         $oOutput->processEmail( $this );
01715     }
01716 
01722     protected function _sendMail()
01723     {
01724         return parent::send();
01725     }
01726 }

Generated on Tue Aug 18 09:21:05 2009 for OXID eShop CE by  doxygen 1.5.5