oxemail.php

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

Generated on Wed Jun 17 12:09:01 2009 for OXID eShop CE by  doxygen 1.5.5