oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006 
00007 
00014 class oxEmail extends phpmailer
00015 {
00016     public $SMTP_PORT = 25;
00017 
00023     protected $_sReminderMailTemplate = "email_owner_reminder_html.tpl";
00024 
00030     protected $_sOrderUserTemplate          = "email_order_cust_html.tpl";
00031 
00037     protected $_sOrderUserPlainTemplate     = "email_order_cust_plain.tpl";
00038 
00044     protected $_sOrderOwnerTemplate         = "email_order_owner_html.tpl";
00045 
00051     protected $_sOrderOwnerPlainTemplate    = "email_order_owner_plain.tpl";
00052 
00053     // #586A - additional templates for more customizable subjects
00054 
00060     protected $_sOrderUserSubjectTemplate   = "email_order_cust_subj.tpl";
00061 
00067     protected $_sOrderOwnerSubjectTemplate  = "email_order_owner_subj.tpl";
00068 
00074     protected $_sOwnerPricealarmTemplate    = "email_pricealarm_owner.tpl";
00075 
00081     protected $_oShop = null;
00082 
00088     protected $_blInlineImgEmail = null;
00089 
00095     protected $_aRecipients = array();
00096 
00102     protected $_aReplies = array();
00103 
00109     protected $_aAttachments = array();
00110 
00114     public function __construct()
00115     {
00116         $myConfig = $this->getConfig();
00117 
00118         $this->_setMailerPluginDir();
00119         $this->setSmtp();
00120 
00121         $this->setUseInlineImages( true );
00122         $this->setMailWordWrap( 100 );
00123 
00124         $this->isHtml( true );
00125         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00126     }
00127 
00133     public function getConfig()
00134     {
00135         if ( $this->_oConfig == null ) {
00136             $this->_oConfig = oxConfig::getInstance();
00137         }
00138 
00139         return $this->_oConfig;
00140     }
00141 
00149     public function setConfig( $oConfig )
00150     {
00151         $this->_oConfig = $oConfig;
00152     }
00153 
00161     public function send()
00162     {
00163         $myConfig = $this->getConfig();
00164         $this->setCharSet();
00165 
00166         if ( $this->_getUseInlineImages() ) {
00167             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00168                                    $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00169         }
00170 
00171         $this->_makeOutputProcessing();
00172 
00173         // try to send mail via SMTP
00174         if ( $this->getMailer() == 'smtp' ) {
00175             $blRet = $this->_sendMail();
00176 
00177             // if sending failed, try to send via mail()
00178             if ( !$blRet ) {
00179                 $this->setMailer( 'mail' );
00180                 $blRet = $this->_sendMail();
00181             }
00182         } else {
00183             // sending mail via mail()
00184             $this->setMailer( 'mail' );
00185             $blRet = $this->_sendMail();
00186         }
00187 
00188         if ( !$blRet ) {
00189             // failed sending, giving up, trying to send notification to shop owner
00190             $this->_sendMailErrorMsg();
00191         }
00192 
00193         return $blRet;
00194     }
00195 
00203     public function setSmtp( $oShop = null )
00204     {
00205         $myConfig = $this->getConfig();
00206         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00207 
00208         if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00209             $this->setMailer( "mail" );
00210             return;
00211         }
00212 
00213         $this->setHost( $oShop->oxshops__oxsmtp->value );
00214         $this->setMailer( "smtp" );
00215 
00216         if ( $oShop->oxshops__oxsmtpuser->value ) {
00217             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00218         }
00219 
00220         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00221             $this->_setSmtpDebug( true );
00222         }
00223     }
00224 
00232     protected function _isValidSmtpHost( $sSmtpHost )
00233     {
00234         $blIsSmtp = false;
00235         if ( $sSmtpHost ) {
00236             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00237                 // closing connection ..
00238                 fclose( $rHandle );
00239             }
00240         }
00241 
00242         return $blIsSmtp;
00243     }
00244 
00253     public function sendOrderEmailToUser( $oOrder )
00254     {
00255         $myConfig = $this->getConfig();
00256 
00257         $sCustHTML  = $this->_sOrderUserTemplate;
00258         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00259 
00260         // add user defined stuff if there is any
00261         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00262 
00263         //set mail params (from, fromName, smtp)
00264         $oShop = $this->_getShop();
00265         $this->_setMailParams( $oShop );
00266 
00267         // P
00268         // setting some deprecated variables
00269         $oOrder->oDelSet = $oOrder->getDelSet();
00270 
00271         // create messages
00272         $smarty = oxUtilsView::getInstance()->getSmarty();
00273         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00274         $smarty->assign( "order", $oOrder);
00275         $smarty->assign( "shop", $oShop );
00276         $smarty->assign( "oViewConf", $oShop );
00277         $smarty->assign( "user", $oOrder->getUser() );
00278         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00279         $smarty->assign( "basket", $oOrder->getBasket() );
00280         $smarty->assign( "payment", $oOrder->getPayment() );
00281         $smarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00282 
00283         //deprecated vars
00284         $smarty->assign( "iswishlist", true);
00285         $smarty->assign( "isreview", true);
00286 
00287         if( $aVoucherList = $oOrder->getVoucherList() ) {
00288             $smarty->assign( "vouchers", $aVoucherList );
00289         }
00290 
00291         $oOutputProcessor = oxNew( "oxoutput" );
00292         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00293 
00294         foreach ( $aNewSmartyArray as $key => $val ) {
00295             $smarty->assign( $key, $val );
00296         }
00297 
00298         $this->setBody( $smarty->fetch( $sCustHTML) );
00299         $this->setAltBody( $smarty->fetch( $sCustPLAIN) );
00300 
00301         // #586A
00302         if ( $smarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00303             $this->setSubject( $smarty->fetch( $this->_sOrderUserSubjectTemplate) );
00304         } else {
00305             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00306         }
00307 
00308         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00309 
00310         $this->setRecipient( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00311         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00312 
00313         $blSuccess = $this->send();
00314 
00315         return $blSuccess;
00316     }
00317 
00326     public function sendOrderEmailToOwner( $oOrder )
00327     {
00328         $myConfig = $this->getConfig();
00329 
00330         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00331         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00332 
00333         // cleanup
00334         $this->_clearMailer();
00335 
00336         // add user defined stuff if there is any
00337         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00338 
00339         // send confirmation to shop owner
00340         $sFullName = $oOrder->getUser()->oxuser__oxfname->value . " " . $oOrder->getUser()->oxuser__oxlname->value;
00341         $this->setFrom( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00342 
00343         $iOrderLang = oxLang::getInstance()->getTplLanguage();
00344 
00345         $oShop = $this->_getShop();
00346 
00347         // if running shop language is different from admin lang. set in config
00348         // we have to load shop in config language
00349         if ( $oShop->getLanguage() != $iOrderLang ) {
00350             $oShop = $this->_getShop( $iOrderLang );
00351         }
00352 
00353         $this->setSmtp( $oShop );
00354 
00355         // create messages
00356         $smarty = oxUtilsView::getInstance()->getSmarty();
00357         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00358         $smarty->assign( "order", $oOrder );
00359         $smarty->assign( "shop", $oShop );
00360         $smarty->assign( "oViewConf", $oShop );
00361         $smarty->assign( "user", $oOrder->getUser() );
00362         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00363         $smarty->assign( "basket", $oOrder->getBasket() );
00364         $smarty->assign( "payment", $oOrder->getPayment() );
00365 
00366         //deprecated var
00367         $smarty->assign( "iswishlist", true);
00368 
00369         if( $oOrder->getVoucherList() )
00370             $smarty->assign( "vouchers", $oOrder->getVoucherList() );
00371 
00372         $oOutputProcessor = oxNew( "oxoutput" );
00373         $aNewSmartyArray = $oOutputProcessor->processViewArray($smarty->get_template_vars(), "oxemail");
00374         foreach ($aNewSmartyArray as $key => $val)
00375             $smarty->assign( $key, $val );
00376 
00377         //path to admin message template file
00378         $sPathToTemplate = $myConfig->getTemplateDir(false, $iOrderLang).'/';
00379 
00380         $this->setBody( $smarty->fetch( $sPathToTemplate.$sOwnerHTML ) );
00381         $this->setAltBody( $smarty->fetch( $sPathToTemplate.$sOwnerPLAIN ) );
00382 
00383         //Sets subject to email
00384         // #586A
00385         if ( $smarty->template_exists( $this->_sOrderOwnerSubjectTemplate) )
00386             $this->setSubject( $smarty->fetch( $this->_sOrderOwnerSubjectTemplate) );
00387         else
00388             $this->setSubject( $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")" );
00389 
00390         $this->setRecipient( $oShop->oxshops__oxowneremail->value, oxLang::getInstance()->translateString("order") );
00391 
00392         if ( $oOrder->getUser()->oxuser__oxusername->value != "admin" )
00393             $this->setReplyTo( $oOrder->getUser()->oxuser__oxusername->value, $sFullName );
00394 
00395         $blSuccess = $this->send();
00396 
00397         // add user history
00398         $oRemark = oxNew( "oxremark" );
00399         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00400         $oRemark->oxremark__oxparentid  = new oxField($oOrder->getUser()->getId(), oxField::T_RAW);
00401         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00402         $oRemark->save();
00403 
00404 
00405         if( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00406             exit();
00407         }
00408 
00409         return $blSuccess;
00410     }
00411 
00420     public function sendRegisterEmail( $oUser )
00421     {
00422         // add user defined stuff if there is any
00423         $oUser = $this->_addUserRegisterEmail( $oUser );
00424 
00425         // shop info
00426         $oShop = $this->_getShop();
00427 
00428         //set mail params (from, fromName, smtp )
00429         $this->_setMailParams( $oShop );
00430 
00431         // create messages
00432         $smarty = oxUtilsView::getInstance()->getSmarty();
00433         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00434         $smarty->assign( "shop", $oShop );
00435         $smarty->assign( "oViewConf", $oShop );
00436         $smarty->assign( "user", $oUser );
00437 
00438         $oOutputProcessor = oxNew( "oxoutput" );
00439         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00440 
00441         foreach ( $aNewSmartyArray as $key => $val ) {
00442             $smarty->assign( $key, $val );
00443         }
00444 
00445         $this->setBody( $smarty->fetch( "email_register_html.tpl") );
00446         $this->setAltBody( $smarty->fetch( "email_register_plain.tpl") );
00447 
00448         $this->setSubject( $oShop->oxshops__oxregistersubject->value );
00449 
00450         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00451 
00452         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00453         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00454 
00455         return $this->send();
00456     }
00457 
00466     public function sendForgotPwdEmail( $sEmailAddress )
00467     {
00468         $myConfig = $this->getConfig();
00469 
00470         // shop info
00471         $oShop = $this->_getShop();
00472 
00473         // add user defined stuff if there is any
00474         $oShop = $this->_addForgotPwdEmail( $oShop);
00475 
00476         //set mail params (from, fromName, smtp)
00477         $this->_setMailParams( $oShop );
00478 
00479         // user
00480         $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and
00481                     oxuser.oxusername = '$sEmailAddress' and oxuser.oxpassword != ''
00482                     order by oxshopid = '".$oShop->getId()."' desc";
00483 
00484         if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00485 
00486             $oUser = oxNew( 'oxuser' );
00487             if ( $oUser->load($sOxId) ) {
00488                 // create messages
00489                 $smarty = oxUtilsView::getInstance()->getSmarty();
00490                 $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00491                 $smarty->assign( "shop", $oShop );
00492                 $smarty->assign( "oViewConf", $oShop );
00493                 $smarty->assign( "user", $oUser );
00494 
00495                 $oOutputProcessor = oxNew( "oxoutput" );
00496                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00497 
00498                 foreach ( $aNewSmartyArray as $key => $val ) {
00499                     $smarty->assign($key, $val);
00500                 }
00501 
00502                 $this->setBody( $smarty->fetch( "email_forgotpwd_html.tpl") );
00503                 $this->setAltBody( $smarty->fetch( "email_forgotpwd_plain.tpl") );
00504 
00505                 //sets subject of email
00506                 $this->setSubject( $oShop->oxshops__oxforgotpwdsubject->value );
00507 
00508                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00509 
00510                 $this->setRecipient( $sEmailAddress, $sFullName );
00511                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00512 
00513                 return $this->send();
00514             }
00515         }
00516 
00517         return false;
00518     }
00519 
00530     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00531     {
00532 
00533         // shop info
00534         $oShop = $this->_getShop();
00535 
00536         //set mail params (from, fromName, smtp)
00537         $this->_setMailParams( $oShop );
00538 
00539         $this->setBody( $sMessage );
00540         $this->setSubject( $sSubject );
00541 
00542         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00543         $this->setFrom( $sEmailAddress, "" );
00544         $this->setReplyTo( $sEmailAddress, "" );
00545 
00546         return $this->send();
00547     }
00548 
00557     public function sendNewsletterDbOptInMail( $oUser )
00558     {
00559 
00560         // add user defined stuff if there is any
00561         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00562 
00563         // shop info
00564         $oShop = $this->_getShop();
00565 
00566         //set mail params (from, fromName, smtp)
00567         $this->_setMailParams( $oShop );
00568 
00569         // create messages
00570         $smarty = oxUtilsView::getInstance()->getSmarty();
00571         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00572         $smarty->assign( "shop", $oShop );
00573         $smarty->assign( "oViewConf", $oShop );
00574         $smarty->assign( "user", $oUser );
00575 
00576         $oOutputProcessor = oxNew( "oxoutput" );
00577         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00578         foreach ( $aNewSmartyArray as $key => $val ) {
00579             $smarty->assign( $key, $val );
00580         }
00581 
00582         $this->setBody( $smarty->fetch("email_newsletteroptin_html.tpl") );
00583         $this->setAltBody( $smarty->fetch( "email_newsletteroptin_plain.tpl") );
00584         $this->setSubject( "Newsletter " . $oShop->oxshops__oxname->value );
00585 
00586         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00587 
00588         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00589         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->value );
00590         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->value );
00591 
00592         return $this->send();
00593     }
00594 
00604     public function sendNewsletterMail( $oNewsLetter, $oUser )
00605     {
00606         // shop info
00607         $oShop = $this->_getShop();
00608 
00609         //set mail params (from, fromName, smtp)
00610         $this->_setMailParams( $oShop );
00611 
00612         $sBody = $oNewsLetter->getHtmlText();
00613 
00614         if ( !empty($sBody) ) {
00615             $this->setBody( $sBody );
00616             $this->setAltBody( $oNewsLetter->getPlainText() );
00617         } else {
00618             $this->isHtml( false );
00619             $this->setBody( $oNewsLetter->getPlainText() );
00620         }
00621 
00622         $this->setSubject( $oNewsLetter->oxnewsletter__oxtitle->value );
00623 
00624         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00625         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00626         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00627 
00628         return $this->send();
00629     }
00630 
00640     public function sendSuggestMail( $oParams, $oProduct )
00641     {
00642         $myConfig = $this->getConfig();
00643 
00644         //sets language of shop
00645         $iCurrLang = 0;
00646         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00647         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00648             $iCurrLang = $iActShopLang;
00649         }
00650 
00651         // shop info
00652         $oShop = $this->_getShop( $iCurrLang );
00653 
00654         //sets language to article
00655         if ( $oProduct->getLanguage() != $iCurrLang ) {
00656             $oProduct->setLanguage( $iCurrLang );
00657             $oProduct->load( $oProduct->getId() );
00658         }
00659 
00660         // mailer stuff
00661         $this->setFrom( $oParams->send_email, $oParams->send_name );
00662         $this->setSMTP();
00663 
00664         // create messages
00665         $smarty = oxUtilsView::getInstance()->getSmarty();
00666         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00667         $smarty->assign( "shop", $oShop );
00668         $smarty->assign( "oViewConf", $oShop );
00669         $smarty->assign( "userinfo", $oParams );
00670         $smarty->assign( "product", $oProduct );
00671 
00672         $oOutputProcessor = oxNew( "oxoutput" );
00673         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00674 
00675         foreach ( $aNewSmartyArray as $key => $val ) {
00676             $smarty->assign( $key, $val );
00677         }
00678 
00679         $this->setBody( $smarty->fetch( "email_suggest_html.tpl") );
00680         $this->setAltBody( $smarty->fetch( "email_suggest_plain.tpl") );
00681         $this->setSubject( $oParams->send_subject );
00682 
00683         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00684         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00685 
00686         return $this->send();
00687     }
00688 
00697     public function sendSendedNowMail( $oOrder )
00698     {
00699         $myConfig = $this->getConfig();
00700 
00701         $iOrderLang = 0;
00702         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00703             $iOrderLang = $oOrder->oxorder__oxlang->value;
00704         }
00705 
00706         // shop info
00707         $oShop = $this->_getShop( $iOrderLang );
00708 
00709         //set mail params (from, fromName, smtp)
00710         $this->_setMailParams( $oShop );
00711 
00712         //override default wrap
00713         //$this->setMailWordWrap( 0 );
00714 
00715         //create messages
00716         $smarty = oxUtilsView::getInstance()->getSmarty();
00717         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00718         $smarty->assign( "shop", $oShop );
00719         $smarty->assign( "oViewConf", $oShop );
00720         $smarty->assign( "order", $oOrder );
00721         $smarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00722 
00723         //deprecated var
00724         $smarty->assign( "isreview", true);
00725 
00726         $oOutputProcessor = oxNew( "oxoutput" );
00727         $aNewSmartyArray = $oOutputProcessor->processViewArray( $smarty->get_template_vars(), "oxemail" );
00728 
00729         foreach ( $aNewSmartyArray as $key => $val ) {
00730             $smarty->assign( $key, $val );
00731         }
00732 
00733         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00734         $aStore['INCLUDE_ANY'] = $smarty->security_settings['INCLUDE_ANY'];
00735         //P
00736         //$aStore['blAdminTemplateLanguage'] = oxLang::getInstance()->getTplLanguage();
00737         $aStore['tpllanguage'] = oxLang::getInstance()->getTplLanguage();
00738         $aStore['lang'] = oxConfig::getParameter( 'lang' );
00739         if ( !isset( $aStore['lang'] ) ) {
00740             $aStore['lang'] = oxSession::getVar( 'lang' );
00741         }
00742 
00743         $smarty->security_settings['INCLUDE_ANY'] = true;
00744 
00745         //Sets path to template file
00746         $sPathToTemplate = $myConfig->getTemplateDir(false, $iOrderLang)."/";
00747 
00748         $this->setBody( $smarty->fetch( $sPathToTemplate."email_sendednow_html.tpl") );
00749         $this->setAltBody( $smarty->fetch( $sPathToTemplate."email_sendednow_plain.tpl") );
00750 
00751         // set it back
00752         $smarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00753 
00754         //Sets subject to email
00755         $this->setSubject( $oShop->oxshops__oxsendednowsubject->value );
00756 
00757         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00758 
00759         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00760         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00761 
00762         return $this->send();
00763     }
00764 
00779     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00780     {
00781 
00782         /* P
00783         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00784         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00785         */
00786 
00787         // shop info
00788         $oShop = $this->_getShop();
00789 
00790         //set mail params (from, fromName, smtp)
00791         $this->_setMailParams( $oShop );
00792 
00793         $this->setBody( $sMessage );
00794         $this->setSubject( $sSubject );
00795 
00796         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00797 
00798         if ( !$sEmailAddress ) {
00799             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00800         }
00801 
00802         $this->setFrom( $sEmailAddress, "" );
00803         $this->setReplyTo( $sEmailAddress, "" );
00804 
00805         //attaching files
00806         $blAttashSucc = true;
00807         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00808         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00809             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00810                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00811             } else {
00812                 $blAttashSucc = false;
00813                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00814             }
00815         }
00816 
00817         if ( !$blAttashSucc ) {
00818             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00819             $this->clearAttachments();
00820             return false;
00821         }
00822 
00823         $aStatus[] = 3;     //"Mailing backup files ...";
00824         $blSend = $this->send();
00825         $this->clearAttachments();
00826 
00827         return $blSend;
00828     }
00829 
00840     public function sendEmail( $sTo, $sSubject, $sBody )
00841     {
00842         //set mail params (from, fromName, smtp)
00843         $this->_setMailParams();
00844 
00845         if ( is_array($sTo) ) {
00846             foreach ($sTo as $sAddress) {
00847                 $this->setRecipient( $sAddress, "" );
00848                 $this->setReplyTo( $sAddress, "" );
00849             }
00850         } else {
00851             $this->setRecipient( $sTo, "" );
00852             $this->setReplyTo( $sTo, "" );
00853         }
00854 
00855         //may be changed later
00856         $this->isHtml( false );
00857 
00858         $this->setSubject( $sSubject );
00859         $this->setBody( $sBody );
00860 
00861         return $this->send();
00862     }
00863 
00871     public function sendStockReminder( $aBasketContents )
00872     {
00873         $myConfig = $this->getConfig();
00874 
00875         $aRemindArticles = array();
00876         foreach ( $aBasketContents as $oBasketItem ) {
00877             $oArticle = $oBasketItem->getArticle();
00878              // reminder not set
00879             if ( !$oArticle->oxarticles__oxremindactiv->value || $oArticle->oxarticles__oxremindactiv->value > 1 ) {
00880                 continue;
00881             }
00882 
00883             // number or articles available is more
00884             if ( $oArticle->oxarticles__oxstock->value > $oArticle->oxarticles__oxremindamount->value ) {
00885                 continue;
00886             }
00887 
00888             $aRemindArticles[] = $oArticle;
00889             $oArticle->disableReminder();
00890         }
00891 
00892         // nothing to remind ...
00893         if ( !count( $aRemindArticles ) ) {
00894             return false;
00895         }
00896         $oShop = $this->_getShop();
00897 
00898         //set mail params (from, fromName, smtp... )
00899         $this->_setMailParams( $oShop );
00900 
00901 
00902         $smarty = oxUtilsView::getInstance()->getSmarty();
00903         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00904         $smarty->assign( "shop", $oShop );
00905         $smarty->assign( "oViewConf", $oShop );
00906         $smarty->assign( "articles", $aRemindArticles );
00907 
00908         //path to admin message template file
00909         $sPathToTemplate = $myConfig->getTemplateDir(false).'/';
00910 
00911         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->value );
00912         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->value );
00913         $this->setBody( $smarty->fetch($sPathToTemplate.$this->_sReminderMailTemplate) );
00914         $this->setAltBody( "" );
00915         $this->setSubject( oxLang::getInstance()->translateString('EMAIL_STOCKREMINDER_SUBJECT') );
00916 
00917         return $this->send();
00918     }
00919 
00928     public function sendWishlistMail( $oParams )
00929     {
00930         $myConfig = $this->getConfig();
00931 
00932         $this->_clearMailer();
00933 
00934         // shop info
00935         $oShop = $this->_getShop();
00936 
00937         // mailer stuff
00938         $this->setFrom( $oParams->send_email, $oParams->send_name );
00939         $this->setSMTP();
00940 
00941         // create messages
00942         $smarty = oxUtilsView::getInstance()->getSmarty();
00943         $smarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00944         $smarty->assign( "shop", $oShop );
00945         $smarty->assign( "oViewConf", $oShop );
00946         $smarty->assign( "userinfo", $oParams );
00947 
00948         $this->setBody( $smarty->fetch( "email_wishlist_html.tpl") );
00949         $this->setAltBody( $smarty->fetch( "email_wishlist_plain.tpl") );
00950         $this->setSubject( $oParams->send_subject );
00951 
00952         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00953         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00954 
00955         return $this->send();
00956     }
00957 
00967     public function sendPriceAlarmNotification( $aParams, $oAlarm )
00968     {
00969         $myConfig = $this->getConfig();
00970 
00971         $this->_clearMailer();
00972         $oShop = $this->_getShop();
00973 
00974         //set mail params (from, fromName, smtp)
00975         $this->_setMailParams( $oShop );
00976 
00977         $oArticle = oxNew( "oxarticle" );
00978         $oArticle->setSkipAbPrice( true );
00979         $oArticle->load( $aParams['aid'] );
00980 
00981         $oCur = $myConfig->getActShopCurrencyObject();
00982 
00983         $iAlarmLang = $oShop->getLanguage();
00984 
00985         // create messages
00986         $smarty = oxUtilsView::getInstance()->getSmarty();
00987         $smarty->assign( "shop", $oShop );
00988         $smarty->assign( "oViewConf", $oShop );
00989         $smarty->assign( "product", $oArticle );
00990         $smarty->assign( "email", $aParams['email']);
00991         $smarty->assign( "bidprice", oxLang::getInstance()->formatCurrency($oAlarm->oxpricealarm__oxprice->value, $oCur) );
00992         $smarty->assign( "currency", $oCur );
00993 
00994         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
00995         $sSubject = oxLang::getInstance()->translateString('EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value;
00996         $this->setSubject( $sSubject );
00997         $this->setBody( $smarty->fetch($this->_sOwnerPricealarmTemplate) );
00998         $this->setFrom( $aParams['email'], "" );
00999         $this->setReplyTo( $aParams['email'], "" );
01000 
01001         return $this->send();
01002     }
01003 
01015     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01016     {
01017         $myConfig = $this->getConfig();
01018 
01019         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $this->getBody(), $matches, PREG_SET_ORDER)) {
01020             if (is_array($matches) && count($matches)) {
01021                 $aImageCache = array();
01022 
01023                 foreach ($matches as $aImage) {
01024 
01025                     $image = $aImage[1];
01026                     $sFileName = '';
01027                     if (strpos($image, $sDynImageDir) === 0) {
01028                         $sFileName = $sAbsDynImageDir.'/' . substr($image, strlen($sDynImageDir)+1);
01029                     } elseif (strpos($image, $sImageDir) === 0) {
01030                         $sFileName = $sAbsImageDir.'/' . substr($image, strlen($sImageDir)+1);
01031                     } elseif (strpos($image, $sImageDirNoSSL) === 0) {
01032                         $sFileName = $sAbsImageDir.'/' . substr($image, strlen($sImageDirNoSSL)+1);
01033                     }
01034 
01035                     if ($sFileName && @is_file($sFileName)) {
01036 
01037                         $sCId = '';
01038                         if (isset($aImageCache[$sFileName]) && $aImageCache[$sFileName]) {
01039                             $sCId = $aImageCache[$sFileName];
01040                         } else {
01041                             $sCId = uniqid(time());
01042                             $sMIME = oxUtils::getInstance()->oxMimeContentType($sFileName);
01043                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01044                                 if ($this->addEmbeddedImage($sFileName, $sCId, "image", "base64", $sMIME)) {
01045                                     $aImageCache[$sFileName] = $sCId;
01046                                 } else {
01047                                     $sCId = '';
01048                                 }
01049                             }
01050                         }
01051                         if ($sCId && $sCId == $aImageCache[$sFileName]) {
01052                             $sReplTag = str_replace($image, 'cid:'.$sCId, $aImage[0]);
01053                             if ($sReplTag) {
01054                                 $this->setBody( str_replace($aImage[0], $sReplTag, $this->getBody()) );
01055                             }
01056                         }
01057                     }
01058                 }
01059             }
01060         }
01061     }
01062 
01070     public function setSubject( $sSubject = null )
01071     {
01072         // A. HTML entites in subjects must be replaced
01073         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01074         $this->Subject = $sSubject;
01075     }
01076 
01082     public function getSubject()
01083     {
01084         return $this->Subject;
01085     }
01086 
01096     public function setBody( $sBody = null, $blClearSid = true )
01097     {
01098         if ( $blClearSid ) {
01099             $sBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01100         }
01101 
01102         $this->Body = $sBody;
01103     }
01104 
01110     public function getBody()
01111     {
01112         return $this->Body;
01113     }
01114 
01124     public function setAltBody( $sAltBody = null, $blClearSid = true )
01125     {
01126         if ( $blClearSid ) {
01127             $sAltBody = eregi_replace("sid=[A-Z0-9\.]+", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01128         }
01129 
01130         // A. alt body is used for plain text emails so we should eliminate HTML entities
01131         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01132         $this->AltBody = $sAltBody;
01133     }
01134 
01140     public function getAltBody()
01141     {
01142         return $this->AltBody;
01143     }
01144 
01153     public function setRecipient( $sAddress = null, $sName = null )
01154     {
01155         // copying values as original class does not allow to access recipients array
01156         $this->_aRecipients[] = array( $sAddress, $sName );
01157 
01158         parent::AddAddress($sAddress, $sName );
01159     }
01160 
01168     public function getRecipient()
01169     {
01170         return $this->_aRecipients;
01171     }
01172 
01179     public function clearAllRecipients()
01180     {
01181         $this->_aRecipients = array();
01182         parent::clearAllRecipients();
01183     }
01184 
01196     public function setReplyTo( $sEmail = null, $sName = null )
01197     {
01198         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01199             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01200         }
01201 
01202         $this->_aReplies[] = array( $sEmail, $sName );
01203         parent::AddReplyTo( $sEmail, $sName );
01204     }
01205 
01211     public function getReplyTo()
01212     {
01213         return $this->_aReplies;
01214     }
01215 
01221     public function clearReplyTos()
01222     {
01223         $this->_aReplies = array();
01224         parent::clearReplyTos();
01225     }
01226 
01235     public function setFrom( $sFromAdress = null, $sFromName = null )
01236     {
01237         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01238         // this is simple but must work
01239         // dodger Task #1532 field "From" in emails from shops
01240         $this->From     = substr($sFromAdress, 0, 150);
01241         $this->FromName = substr($sFromName, 0, 150);
01242     }
01243 
01249     public function getFrom()
01250     {
01251         return $this->From;
01252     }
01253 
01259     public function getFromName()
01260     {
01261         return $this->FromName;
01262     }
01263 
01272     public function setCharSet( $sCharSet = null )
01273     {
01274         if ( !empty($sCharSet) ) {
01275             $this->CharSet = $sCharSet;
01276         } else {
01277             $this->CharSet = oxLang::getInstance()->translateString("charset");
01278         }
01279     }
01280 
01286     public function getCharSet()
01287     {
01288         return $this->CharSet;
01289     }
01290 
01298     public function setMailer( $sMailer = null )
01299     {
01300         $this->Mailer = $sMailer;
01301     }
01302 
01308     public function getMailer()
01309     {
01310         return $this->Mailer;
01311     }
01312 
01320     public function setHost( $sHost = null )
01321     {
01322         $this->Host = $sHost;
01323     }
01324 
01330     public function getErrorInfo()
01331     {
01332         return $this->ErrorInfo;
01333     }
01334 
01343     public function setMailWordWrap( $iWordWrap = null )
01344     {
01345         $this->WordWrap = $iWordWrap;
01346     }
01347 
01355     public function setUseInlineImages( $blUseImages = null )
01356     {
01357         $this->_blInlineImgEmail = $blUseImages;
01358     }
01359 
01370     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01371     {
01372         $sFullPath = $sAttPath . $sAttFile;
01373 
01374         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01375         return parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01376     }
01377 
01389     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01390     {
01391         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01392         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01393     }
01394 
01400     public function getAttachments()
01401     {
01402         return $this->_aAttachments;
01403     }
01404 
01410     public function clearAttachments()
01411     {
01412         $this->_aAttachments = array();
01413         return parent::ClearAttachments();
01414     }
01415 
01425     public function headerLine($sName, $sValue) 
01426     {
01427         if (stripos($sName, 'X-') !== false) {
01428             return;
01429         }
01430         return parent::headerLine($sName, $sValue);
01431     }
01432 
01438     protected function _getUseInlineImages()
01439     {
01440         return $this->_blInlineImgEmail;
01441     }
01442 
01448     protected function _sendMailErrorMsg()
01449     {
01450         // build addresses
01451         $sToAdress  = "";
01452         $sToName    = "";
01453 
01454         $aRecipients = $this->getRecipient();
01455 
01456         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01457 
01458         foreach ( $aRecipients as $aEMail ) {
01459             $sOwnerMessage .= $aEMail[0];
01460             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01461             $sOwnerMessage .= " \n ";
01462         }
01463         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01464 
01465         // shop info
01466         $oShop = $this->_getShop();
01467 
01468         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01469 
01470         return $blRet;
01471     }
01472 
01482     protected function _addUserInfoOrderEMail( $oOrder )
01483     {
01484         return $oOrder;
01485     }
01486 
01496     protected function _addUserRegisterEmail( $oUser )
01497     {
01498         return $oUser;
01499     }
01500 
01510     protected function _addForgotPwdEmail( $oShop )
01511     {
01512         return $oShop;
01513     }
01514 
01524     protected function _addNewsletterDbOptInMail( $oUser )
01525     {
01526         return $oUser;
01527     }
01528 
01534     protected function _clearMailer()
01535     {
01536         $this->clearAllRecipients();
01537         $this->clearReplyTos();
01538         $this->clearAttachments();
01539 
01540         //workaround for phpmailer as it doesn't cleanup as it should
01541         $this->error_count = 0;
01542         $this->ErrorInfo   = '';
01543     }
01544 
01552     protected function _setMailParams( $oShop = null )
01553     {
01554         $this->_clearMailer();
01555 
01556         if ( !$oShop ) {
01557             $oShop = $this->_getShop();
01558         }
01559 
01560         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value );
01561         $this->setSmtp( $oShop );
01562     }
01563 
01572     protected function _getShop( $iLangId = null )
01573     {
01574         $myConfig = $this->getConfig();
01575         if ( !isset($iLangId) ) {
01576             $iLangId = 0;
01577             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01578             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01579                 $iLangId = $iActShopLang;
01580             }
01581         }
01582         if ( isset($this->_oShop) && $this->_oShop ) {
01583             // if oShop already setted and reqesting oShop with same language as current oShop,
01584             // or wihtout lang param, return oShop object
01585             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01586                 return $this->_oShop;
01587             }
01588         }
01589 
01590         $this->_oShop = oxNew( 'oxshop' );
01591 
01592         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01593 
01594         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01595 
01596         $oView = $myConfig->getActiveView();
01597         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01598 
01599         return $this->_oShop;
01600     }
01601 
01610     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01611     {
01612         $this->SMTPAuth = true;
01613         $this->Username = $sUserName;
01614         $this->Password = $sUserPassword;
01615     }
01616 
01624     protected function _setSmtpDebug( $blDebug = null )
01625     {
01626         $this->SMTPDebug = $blDebug;
01627     }
01628 
01634     protected function _setMailerPluginDir()
01635     {
01636         $this->PluginDir = getShopBasePath() . "core/phpmailer/";
01637     }
01638 
01645     protected function _makeOutputProcessing()
01646     {
01647         $oOutput = oxNew( "oxoutput" );
01648         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01649         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01650         $oOutput->processEmail( $this );
01651     }
01652 
01658     protected function _sendMail()
01659     {
01660         return parent::send();
01661     }
01662 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5