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         //enabling exception handling in phpmailer class
00121         parent::__construct( true );
00122 
00123         $myConfig = $this->getConfig();
00124 
00125         $this->_setMailerPluginDir();
00126         $this->setSmtp();
00127 
00128         $this->setUseInlineImages( true );
00129         $this->setMailWordWrap( 100 );
00130 
00131         $this->isHtml( true );
00132         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00133     }
00134 
00146     public function __call( $sMethod, $aArgs )
00147     {
00148         if ( defined( 'OXID_PHP_UNIT' ) ) {
00149             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00150                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00151             }
00152             if ( method_exists( $this, $sMethod)) {
00153                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00154             }
00155         }
00156 
00157         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00158     }
00159 
00165     public function getConfig()
00166     {
00167         if ( $this->_oConfig == null ) {
00168             $this->_oConfig = oxConfig::getInstance();
00169         }
00170 
00171         return $this->_oConfig;
00172     }
00173 
00181     public function setConfig( $oConfig )
00182     {
00183         $this->_oConfig = $oConfig;
00184     }
00185 
00193     public function send()
00194     {
00195         // if no recipients found, skipping sending
00196         if ( count( $this->getRecipient() ) < 1 ) {
00197             return false;
00198         }
00199 
00200         $myConfig = $this->getConfig();
00201         $this->setCharSet();
00202 
00203         if ( $this->_getUseInlineImages() ) {
00204             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getNoSSLImageDir( isAdmin() ), $myConfig->getDynImageDir(),
00205                                    $myConfig->getAbsImageDir(), $myConfig->getAbsDynImageDir());
00206         }
00207 
00208         $this->_makeOutputProcessing();
00209 
00210         // try to send mail via SMTP
00211         if ( $this->getMailer() == 'smtp' ) {
00212             $blRet = $this->_sendMail();
00213 
00214             // if sending failed, try to send via mail()
00215             if ( !$blRet ) {
00216                 $this->setMailer( 'mail' );
00217                 $blRet = $this->_sendMail();
00218             }
00219         } else {
00220             // sending mail via mail()
00221             $this->setMailer( 'mail' );
00222             $blRet = $this->_sendMail();
00223         }
00224 
00225         if ( !$blRet ) {
00226             // failed sending, giving up, trying to send notification to shop owner
00227             $this->_sendMailErrorMsg();
00228         }
00229 
00230         return $blRet;
00231     }
00232 
00240     public function setSmtp( $oShop = null )
00241     {
00242         $myConfig = $this->getConfig();
00243         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00244 
00245         if ( !$this->_isValidSmtpHost( $oShop->oxshops__oxsmtp->value ) ) {
00246             $this->setMailer( "mail" );
00247             return;
00248         }
00249 
00250         $this->setHost( $oShop->oxshops__oxsmtp->value );
00251         $this->setMailer( "smtp" );
00252 
00253         if ( $oShop->oxshops__oxsmtpuser->value ) {
00254             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00255         }
00256 
00257         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00258             $this->_setSmtpDebug( true );
00259         }
00260     }
00261 
00269     protected function _isValidSmtpHost( $sSmtpHost )
00270     {
00271         $blIsSmtp = false;
00272         if ( $sSmtpHost ) {
00273             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $this->SMTP_PORT, $iErrNo, $sErrStr, 30 )) ) {
00274                 // closing connection ..
00275                 fclose( $rHandle );
00276             }
00277         }
00278 
00279         return $blIsSmtp;
00280     }
00281 
00291     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00292     {
00293         $myConfig = $this->getConfig();
00294 
00295         $sCustHTML  = $this->_sOrderUserTemplate;
00296         $sCustPLAIN = $this->_sOrderUserPlainTemplate;
00297 
00298         // add user defined stuff if there is any
00299         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00300 
00301         //set mail params (from, fromName, smtp)
00302         $oShop = $this->_getShop();
00303         $this->_setMailParams( $oShop );
00304 
00305         // P
00306         // setting some deprecated variables
00307         $oOrder->oDelSet = $oOrder->getDelSet();
00308 
00309         $oUser = $oOrder->getOrderUser();
00310         // create messages
00311         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00312         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00313         $oSmarty->assign( "order", $oOrder);
00314         $oSmarty->assign( "shop", $oShop );
00315         $oSmarty->assign( "oViewConf", $oShop );
00316         $oSmarty->assign( "user", $oUser );
00317         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00318         $oSmarty->assign( "basket", $oOrder->getBasket() );
00319         $oSmarty->assign( "payment", $oOrder->getPayment() );
00320         if ( $oUser ) {
00321             $oSmarty->assign( "reviewuser", $oUser->getReviewUserHash($oUser->getId()) );
00322         }
00323         $oSmarty->assign( "paymentinfo", $myConfig->getActiveShop() );
00324 
00325         //deprecated vars
00326         $oSmarty->assign( "iswishlist", true);
00327         $oSmarty->assign( "isreview", true);
00328 
00329         if ( $aVoucherList = $oOrder->getVoucherList() ) {
00330             $oSmarty->assign( "vouchers", $aVoucherList );
00331         }
00332 
00333         $oOutputProcessor = oxNew( "oxoutput" );
00334         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00335 
00336         foreach ( $aNewSmartyArray as $key => $val ) {
00337             $oSmarty->assign( $key, $val );
00338         }
00339 
00340         $this->setBody( $oSmarty->fetch( $sCustHTML) );
00341         $this->setAltBody( $oSmarty->fetch( $sCustPLAIN) );
00342 
00343         // #586A
00344         if ( $sSubject === null ) {
00345             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00346                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00347             } else {
00348                 $sSubject = $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")";
00349             }
00350         }
00351 
00352         $this->setSubject( $sSubject );
00353 
00354         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00355 
00356         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00357         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00358 
00359         $blSuccess = $this->send();
00360 
00361         return $blSuccess;
00362     }
00363 
00373     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00374     {
00375         $myConfig = $this->getConfig();
00376 
00377         $oShop = $this->_getShop();
00378 
00379         $sOwnerHTML  = $this->_sOrderOwnerTemplate;
00380         $sOwnerPLAIN = $this->_sOrderOwnerPlainTemplate;
00381 
00382         // cleanup
00383         $this->_clearMailer();
00384 
00385         // add user defined stuff if there is any
00386         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00387 
00388         // send confirmation to shop owner
00389         $sFullName = $oOrder->getOrderUser()->oxuser__oxfname->value . " " . $oOrder->getOrderUser()->oxuser__oxlname->value;
00390         $this->setFrom( $oOrder->getOrderUser()->oxuser__oxusername->value, $sFullName );
00391 
00392         $oLang = oxLang::getInstance();
00393         $iOrderLang = $oLang->getTplLanguage();
00394 
00395         // if running shop language is different from admin lang. set in config
00396         // we have to load shop in config language
00397         if ( $oShop->getLanguage() != $iOrderLang ) {
00398             $oShop = $this->_getShop( $iOrderLang );
00399         }
00400 
00401         $this->setSmtp( $oShop );
00402 
00403         // create messages
00404         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00405         $oSmarty->assign( "charset", $oLang->translateString("charset"));
00406         $oSmarty->assign( "order", $oOrder );
00407         $oSmarty->assign( "shop", $oShop );
00408         $oSmarty->assign( "oViewConf", $oShop );
00409         $oSmarty->assign( "user", $oOrder->getOrderUser() );
00410         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00411         $oSmarty->assign( "basket", $oOrder->getBasket() );
00412         $oSmarty->assign( "payment", $oOrder->getPayment() );
00413 
00414         //deprecated var
00415         $oSmarty->assign( "iswishlist", true);
00416 
00417         if( $oOrder->getVoucherList() )
00418             $oSmarty->assign( "vouchers", $oOrder->getVoucherList() );
00419 
00420         $oOutputProcessor = oxNew( "oxoutput" );
00421         $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
00422         foreach ($aNewSmartyArray as $key => $val)
00423             $oSmarty->assign( $key, $val );
00424 
00425         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath($sOwnerHTML,false) ) );
00426         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath($sOwnerPLAIN,false) ) );
00427 
00428         //Sets subject to email
00429         // #586A
00430         if ( $sSubject === null ) {
00431             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00432                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00433             } else {
00434                  $sSubject = $oShop->oxshops__oxordersubject->value." (#".$oOrder->oxorder__oxordernr->value.")";
00435             }
00436         }
00437 
00438         $this->setSubject( $sSubject );
00439         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00440 
00441         if ( $oOrder->getOrderUser()->oxuser__oxusername->value != "admin" )
00442             $this->setReplyTo( $oOrder->getOrderUser()->oxuser__oxusername->value, $sFullName );
00443 
00444         $blSuccess = $this->send();
00445 
00446         // add user history
00447         $oRemark = oxNew( "oxremark" );
00448         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00449         $oRemark->oxremark__oxparentid  = new oxField($oOrder->getOrderUser()->getId(), oxField::T_RAW);
00450         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00451         $oRemark->save();
00452 
00453 
00454         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00455             exit();
00456         }
00457 
00458         return $blSuccess;
00459     }
00460 
00470     public function sendRegisterEmail( $oUser, $sSubject = null )
00471     {
00472         // add user defined stuff if there is any
00473         $oUser = $this->_addUserRegisterEmail( $oUser );
00474 
00475         // shop info
00476         $oShop = $this->_getShop();
00477 
00478         //set mail params (from, fromName, smtp )
00479         $this->_setMailParams( $oShop );
00480 
00481         // create messages
00482         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00483         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00484         $oSmarty->assign( "shop", $oShop );
00485         $oSmarty->assign( "oViewConf", $oShop );
00486         $oSmarty->assign( "user", $oUser );
00487 
00488         $oOutputProcessor = oxNew( "oxoutput" );
00489         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00490 
00491         foreach ( $aNewSmartyArray as $key => $val ) {
00492             $oSmarty->assign( $key, $val );
00493         }
00494 
00495         $this->setBody( $oSmarty->fetch( "email_register_html.tpl") );
00496         $this->setAltBody( $oSmarty->fetch( "email_register_plain.tpl") );
00497 
00498         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->value );
00499 
00500         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00501 
00502         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00503         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00504 
00505         return $this->send();
00506     }
00507 
00517     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00518     {
00519         $myConfig = $this->getConfig();
00520         $oDb = oxDb::getDb();
00521 
00522         // shop info
00523         $oShop = $this->_getShop();
00524 
00525         // add user defined stuff if there is any
00526         $oShop = $this->_addForgotPwdEmail( $oShop);
00527 
00528         //set mail params (from, fromName, smtp)
00529         $this->_setMailParams( $oShop );
00530 
00531         // user
00532         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00533         $sOrder = "";
00534         if (oxConfig::getInstance()->getConfigParam( 'blMallUsers' )) {
00535             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00536         } else {
00537             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00538         }
00539 
00540         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00541         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00542 
00543             $oUser = oxNew( 'oxuser' );
00544             if ( $oUser->load($sOxId) ) {
00545                 // create messages
00546                 $oSmarty = oxUtilsView::getInstance()->getSmarty();
00547                 $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset"));
00548                 $oSmarty->assign( "shop", $oShop );
00549                 $oSmarty->assign( "oViewConf", $oShop );
00550                 $oSmarty->assign( "user", $oUser );
00551 
00552                 $oOutputProcessor = oxNew( "oxoutput" );
00553                 $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00554 
00555                 foreach ( $aNewSmartyArray as $key => $val ) {
00556                     $oSmarty->assign($key, $val);
00557                 }
00558 
00559                 $this->setBody( $oSmarty->fetch( "email_forgotpwd_html.tpl") );
00560                 $this->setAltBody( $oSmarty->fetch( "email_forgotpwd_plain.tpl") );
00561 
00562                 //sets subject of email
00563                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->value );
00564 
00565                 $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00566 
00567                 $this->setRecipient( $sEmailAddress, $sFullName );
00568                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00569 
00570                 return $this->send();
00571             }
00572         }
00573 
00574         return false;
00575     }
00576 
00587     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00588     {
00589 
00590         // shop info
00591         $oShop = $this->_getShop();
00592 
00593         //set mail params (from, fromName, smtp)
00594         $this->_setMailParams( $oShop );
00595 
00596         $this->setBody( $sMessage );
00597         $this->setSubject( $sSubject );
00598 
00599         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00600         $this->setFrom( $sEmailAddress, "" );
00601         $this->setReplyTo( $sEmailAddress, "" );
00602 
00603         return $this->send();
00604     }
00605 
00615     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00616     {
00617         $oLang = oxLang::getInstance();
00618 
00619         // add user defined stuff if there is any
00620         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00621 
00622         // shop info
00623         $oShop = $this->_getShop();
00624 
00625         //set mail params (from, fromName, smtp)
00626         $this->_setMailParams( $oShop );
00627 
00628         // create messages
00629         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00630         $oSmarty->assign( "charset", $oLang->translateString("charset"));
00631         $oSmarty->assign( "shop", $oShop );
00632         $oSmarty->assign( "oViewConf", $oShop );
00633         $oSmarty->assign( "user", $oUser );
00634 
00635         $oOutputProcessor = oxNew( "oxoutput" );
00636         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00637         foreach ( $aNewSmartyArray as $key => $val ) {
00638             $oSmarty->assign( $key, $val );
00639         }
00640 
00641         $this->setBody( $oSmarty->fetch("email_newsletteroptin_html.tpl") );
00642         $this->setAltBody( $oSmarty->fetch( "email_newsletteroptin_plain.tpl") );
00643         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00644 
00645         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00646 
00647         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00648         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00649         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00650 
00651         return $this->send();
00652     }
00653 
00664     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00665     {
00666         // shop info
00667         $oShop = $this->_getShop();
00668 
00669         //set mail params (from, fromName, smtp)
00670         $this->_setMailParams( $oShop );
00671 
00672         $sBody = $oNewsLetter->getHtmlText();
00673 
00674         if ( !empty($sBody) ) {
00675             $this->setBody( $sBody );
00676             $this->setAltBody( $oNewsLetter->getPlainText() );
00677         } else {
00678             $this->isHtml( false );
00679             $this->setBody( $oNewsLetter->getPlainText() );
00680         }
00681 
00682         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->value );
00683 
00684         $sFullName = $oUser->oxuser__oxfname->value . " " . $oUser->oxuser__oxlname->value;
00685         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00686         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00687 
00688         return $this->send();
00689     }
00690 
00700     public function sendSuggestMail( $oParams, $oProduct )
00701     {
00702         $myConfig = $this->getConfig();
00703 
00704         //sets language of shop
00705         $iCurrLang = 0;
00706         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00707         if ( isset($iActShopLang) && $iActShopLang != $iCurrLang ) {
00708             $iCurrLang = $iActShopLang;
00709         }
00710 
00711         // shop info
00712         $oShop = $this->_getShop( $iCurrLang );
00713 
00714         //sets language to article
00715         if ( $oProduct->getLanguage() != $iCurrLang ) {
00716             $oProduct->setLanguage( $iCurrLang );
00717             $oProduct->load( $oProduct->getId() );
00718         }
00719 
00720         // mailer stuff
00721         $this->setFrom( $oParams->send_email, $oParams->send_name );
00722         $this->setSMTP();
00723 
00724         // create messages
00725         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00726         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00727         $oSmarty->assign( "shop", $oShop );
00728         $oSmarty->assign( "oViewConf", $oShop );
00729         $oSmarty->assign( "userinfo", $oParams );
00730         $oSmarty->assign( "product", $oProduct );
00731 
00732         $oOutputProcessor = oxNew( "oxoutput" );
00733         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00734 
00735         foreach ( $aNewSmartyArray as $key => $val ) {
00736             $oSmarty->assign( $key, $val );
00737         }
00738 
00739         $this->setBody( $oSmarty->fetch( "email_suggest_html.tpl") );
00740         $this->setAltBody( $oSmarty->fetch( "email_suggest_plain.tpl") );
00741         $this->setSubject( $oParams->send_subject );
00742 
00743         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00744         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00745 
00746         return $this->send();
00747     }
00748 
00758     public function sendSendedNowMail( $oOrder, $sSubject = null )
00759     {
00760         $myConfig = $this->getConfig();
00761 
00762         $iOrderLang = 0;
00763         if ( isset($oOrder->oxorder__oxlang->value) && $oOrder->oxorder__oxlang->value ) {
00764             $iOrderLang = $oOrder->oxorder__oxlang->value;
00765         }
00766 
00767         // shop info
00768         $oShop = $this->_getShop( $iOrderLang );
00769 
00770         //set mail params (from, fromName, smtp)
00771         $this->_setMailParams( $oShop );
00772 
00773         //override default wrap
00774         //$this->setMailWordWrap( 0 );
00775 
00776         //create messages
00777         $oLang = oxLang::getInstance();
00778         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00779         $oSmarty->assign( "charset", $oLang->translateString("charset"));
00780         $oSmarty->assign( "shop", $oShop );
00781         $oSmarty->assign( "oViewConf", $oShop );
00782         $oSmarty->assign( "order", $oOrder );
00783         $oSmarty->assign( "currency", $myConfig->getActShopCurrencyObject() );
00784 
00785         //deprecated var
00786         $oSmarty->assign( "isreview", true);
00787         $oUser = oxNew( 'oxuser' );
00788         $oSmarty->assign( "reviewuser", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
00789 
00790         $oOutputProcessor = oxNew( "oxoutput" );
00791         $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
00792 
00793         foreach ( $aNewSmartyArray as $key => $val ) {
00794             $oSmarty->assign( $key, $val );
00795         }
00796 
00797         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
00798         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
00799         //V send email in order language
00800         $iOldTplLang = $oLang->getTplLanguage();
00801         $iOldBaseLang = $oLang->getTplLanguage();
00802         $oLang->setTplLanguage( $iOrderLang );
00803         $oLang->setBaseLanguage( $iOrderLang );
00804 
00805         $oSmarty->security_settings['INCLUDE_ANY'] = true;
00806 
00807         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath("email_sendednow_html.tpl",false)) );
00808         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath("email_sendednow_plain.tpl",false)) );
00809         $oLang->setTplLanguage( $iOldTplLang );
00810         $oLang->setBaseLanguage( $iOldBaseLang );
00811         // set it back
00812         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
00813 
00814         //Sets subject to email
00815         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->value );
00816 
00817         $sFullName = $oOrder->oxorder__oxbillfname->value . " " . $oOrder->oxorder__oxbilllname->value;
00818 
00819         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
00820         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00821         return $this->send();
00822     }
00823 
00838     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
00839     {
00840 
00841         /* P
00842         $sMailMessage = $myConfig->getConfigParam( 'sMailMessage' );
00843         $sMessage = ( !empty($sMailMessage) ) ? $sMailMessage : "" ;
00844         */
00845 
00846         // shop info
00847         $oShop = $this->_getShop();
00848 
00849         //set mail params (from, fromName, smtp)
00850         $this->_setMailParams( $oShop );
00851 
00852         $this->setBody( $sMessage );
00853         $this->setSubject( $sSubject );
00854 
00855         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00856 
00857         if ( !$sEmailAddress ) {
00858             $sEmailAddress = $oShop->oxshops__oxowneremail->value;
00859         }
00860 
00861         $this->setFrom( $sEmailAddress, "" );
00862         $this->setReplyTo( $sEmailAddress, "" );
00863 
00864         //attaching files
00865         $blAttashSucc = true;
00866         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
00867         foreach ( $aAttFiles as $iNum => $sAttFile ) {
00868             if ( file_exists($sAttPath . $sAttFile) && is_file($sAttPath . $sAttFile) ) {
00869                 $blAttashSucc = $this->addAttachment( $sAttPath, $sAttFile );
00870             } else {
00871                 $blAttashSucc = false;
00872                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
00873             }
00874         }
00875 
00876         if ( !$blAttashSucc ) {
00877             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
00878             $this->clearAttachments();
00879             return false;
00880         }
00881 
00882         $aStatus[] = 3;     //"Mailing backup files ...";
00883         $blSend = $this->send();
00884         $this->clearAttachments();
00885 
00886         return $blSend;
00887     }
00888 
00899     public function sendEmail( $sTo, $sSubject, $sBody )
00900     {
00901         //set mail params (from, fromName, smtp)
00902         $this->_setMailParams();
00903 
00904         if ( is_array($sTo) ) {
00905             foreach ($sTo as $sAddress) {
00906                 $this->setRecipient( $sAddress, "" );
00907                 $this->setReplyTo( $sAddress, "" );
00908             }
00909         } else {
00910             $this->setRecipient( $sTo, "" );
00911             $this->setReplyTo( $sTo, "" );
00912         }
00913 
00914         //may be changed later
00915         $this->isHtml( false );
00916 
00917         $this->setSubject( $sSubject );
00918         $this->setBody( $sBody );
00919 
00920         return $this->send();
00921     }
00922 
00931     public function sendStockReminder( $aBasketContents, $sSubject = null )
00932     {
00933         $blSend = false;
00934 
00935         $oArticleList = oxNew( "oxarticlelist" );
00936         $oArticleList->loadStockRemindProducts( $aBasketContents );
00937 
00938         // nothing to remind?
00939         if ( $oArticleList->count() ) {
00940             $oShop = $this->_getShop();
00941 
00942             //set mail params (from, fromName, smtp... )
00943             $this->_setMailParams( $oShop );
00944             $oLang = oxLang::getInstance();
00945 
00946             $oSmarty = oxUtilsView::getInstance()->getSmarty();
00947             $oSmarty->assign( "charset", $oLang->translateString( "charset" ) );
00948             $oSmarty->assign( "shop", $oShop );
00949             $oSmarty->assign( "oViewConf", $oShop );
00950             $oSmarty->assign( "articles", $oArticleList );
00951 
00952             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00953             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00954             $this->setBody( $oSmarty->fetch( $sPathToTemplate . $this->getConfig()->getTemplatePath($this->_sReminderMailTemplate,false) ) );
00955             $this->setAltBody( "" );
00956             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
00957 
00958             $blSend = $this->send();
00959         }
00960 
00961         return $blSend;
00962     }
00963 
00972     public function sendWishlistMail( $oParams )
00973     {
00974         $myConfig = $this->getConfig();
00975 
00976         $this->_clearMailer();
00977 
00978         // shop info
00979         $oShop = $this->_getShop();
00980 
00981         // mailer stuff
00982         $this->setFrom( $oParams->send_email, $oParams->send_name );
00983         $this->setSMTP();
00984 
00985         // create messages
00986         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00987         $oSmarty->assign( "charset", oxLang::getInstance()->translateString("charset") );
00988         $oSmarty->assign( "shop", $oShop );
00989         $oSmarty->assign( "oViewConf", $oShop );
00990         $oSmarty->assign( "userinfo", $oParams );
00991 
00992         $this->setBody( $oSmarty->fetch( "email_wishlist_html.tpl") );
00993         $this->setAltBody( $oSmarty->fetch( "email_wishlist_plain.tpl") );
00994         $this->setSubject( $oParams->send_subject );
00995 
00996         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00997         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00998 
00999         return $this->send();
01000     }
01001 
01012     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01013     {
01014         $this->_clearMailer();
01015         $oShop = $this->_getShop();
01016 
01017         //set mail params (from, fromName, smtp)
01018         $this->_setMailParams( $oShop );
01019 
01020         $iAlarmLang = $oShop->getLanguage();
01021 
01022         $oArticle = oxNew( "oxarticle" );
01023         $oArticle->setSkipAbPrice( true );
01024         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01025 
01026         $oCur  = $this->getConfig()->getActShopCurrencyObject();
01027         $oLang = oxLang::getInstance();
01028 
01029         // create messages
01030         $oSmarty = oxUtilsView::getInstance()->getSmarty();
01031         $oSmarty->assign( "shop", $oShop );
01032         $oSmarty->assign( "oViewConf", $oShop );
01033         $oSmarty->assign( "product", $oArticle );
01034         $oSmarty->assign( "email", $aParams['email']);
01035         $oSmarty->assign( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01036         $oSmarty->assign( "currency", $oCur );
01037 
01038         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01039         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->value );
01040         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01041         $this->setFrom( $aParams['email'], "" );
01042         $this->setReplyTo( $aParams['email'], "" );
01043 
01044         return $this->send();
01045     }
01046 
01058     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01059     {
01060         $sBody = $this->getBody();
01061         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01062 
01063             $oFileUtils = oxUtilsFile::getInstance();
01064             $blReSetBody = false;
01065 
01066             // preparing imput
01067             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01068             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01069             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01070 
01071             if (is_array($matches) && count($matches)) {
01072                 $aImageCache = array();
01073                 $myUtils = oxUtils::getInstance();
01074                 $myUtilsObject = oxUtilsObject::getInstance();
01075 
01076                 foreach ($matches as $aImage) {
01077 
01078                     $image = $aImage[1];
01079                     $sFileName = '';
01080                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01081                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01082                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01083                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01084                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01085                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01086                     }
01087 
01088                     if ($sFileName && @is_file($sFileName)) {
01089                         $sCId = '';
01090                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01091                             $sCId = $aImageCache[$sFileName];
01092                         } else {
01093                             $sCId = $myUtilsObject->generateUID();
01094                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01095                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01096                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01097                                     $aImageCache[$sFileName] = $sCId;
01098                                 } else {
01099                                     $sCId = '';
01100                                 }
01101                             }
01102                         }
01103                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01104                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01105                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01106                                 $blReSetBody = true;
01107                             }
01108                         }
01109                     }
01110                 }
01111             }
01112 
01113             if ( $blReSetBody ) {
01114                 $this->setBody( $sBody );
01115             }
01116         }
01117     }
01118 
01126     public function setSubject( $sSubject = null )
01127     {
01128         // A. HTML entites in subjects must be replaced
01129         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01130 
01131         $this->set( "Subject", $sSubject );
01132     }
01133 
01139     public function getSubject()
01140     {
01141         return $this->Subject;
01142     }
01143 
01153     public function setBody( $sBody = null, $blClearSid = true )
01154     {
01155         if ( $blClearSid ) {
01156             $sBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sBody);
01157         }
01158 
01159         $this->set( "Body", $sBody );
01160     }
01161 
01167     public function getBody()
01168     {
01169         return $this->Body;
01170     }
01171 
01181     public function setAltBody( $sAltBody = null, $blClearSid = true )
01182     {
01183         if ( $blClearSid ) {
01184             $sAltBody = preg_replace("/sid=[A-Z0-9\.]+/i", "sid=x&amp;shp=" . $this->getConfig()->getShopId(), $sAltBody);
01185         }
01186 
01187         // A. alt body is used for plain text emails so we should eliminate HTML entities
01188         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01189 
01190         $this->set( "AltBody", $sAltBody );
01191     }
01192 
01198     public function getAltBody()
01199     {
01200         return $this->AltBody;
01201     }
01202 
01211     public function setRecipient( $sAddress = null, $sName = null )
01212     {
01213         try {
01214             parent::AddAddress( $sAddress, $sName );
01215 
01216             // copying values as original class does not allow to access recipients array
01217             $this->_aRecipients[] = array( $sAddress, $sName );
01218         } catch( Exception $oEx ) {
01219             return;
01220         }
01221     }
01222 
01230     public function getRecipient()
01231     {
01232         return $this->_aRecipients;
01233     }
01234 
01241     public function clearAllRecipients()
01242     {
01243         $this->_aRecipients = array();
01244         parent::clearAllRecipients();
01245     }
01246 
01258     public function setReplyTo( $sEmail = null, $sName = null )
01259     {
01260         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01261             $sEmail = $this->_oShop->oxshops__oxorderemail->value;
01262         }
01263 
01264         $this->_aReplies[] = array( $sEmail, $sName );
01265 
01266         try {
01267             parent::addReplyTo( $sEmail, $sName );
01268         } catch( Exception $oEx ) {
01269             return;
01270         }
01271     }
01272 
01278     public function getReplyTo()
01279     {
01280         return $this->_aReplies;
01281     }
01282 
01288     public function clearReplyTos()
01289     {
01290         $this->_aReplies = array();
01291         parent::clearReplyTos();
01292     }
01293 
01302     public function setFrom( $sFromAdress, $sFromName = null )
01303     {
01304         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01305         // this is simple but must work
01306         // dodger Task #1532 field "From" in emails from shops
01307         $sFromAdress = substr($sFromAdress, 0, 150);
01308         $sFromName   = substr($sFromName, 0, 150);
01309 
01310         try {
01311             parent::setFrom( $sFromAdress, $sFromName );
01312         } catch( Exception $oEx ) {
01313             return;
01314         }
01315     }
01316 
01322     public function getFrom()
01323     {
01324         return $this->From;
01325     }
01326 
01332     public function getFromName()
01333     {
01334         return $this->FromName;
01335     }
01336 
01345     public function setCharSet( $sCharSet = null )
01346     {
01347         if ( empty($sCharSet) ) {
01348             $sCharSet = oxLang::getInstance()->translateString( "charset" );
01349         }
01350 
01351         $this->set( "CharSet", $sCharSet );
01352     }
01353 
01359     public function getCharSet()
01360     {
01361         return $this->CharSet;
01362     }
01363 
01371     public function setMailer( $sMailer = null )
01372     {
01373         $this->set( "Mailer", $sMailer );
01374     }
01375 
01381     public function getMailer()
01382     {
01383         return $this->Mailer;
01384     }
01385 
01393     public function setHost( $sHost = null )
01394     {
01395         $this->set( "Host", $sHost );
01396     }
01397 
01403     public function getErrorInfo()
01404     {
01405         return $this->ErrorInfo;
01406     }
01407 
01416     public function setMailWordWrap( $iWordWrap = null )
01417     {
01418         $this->set( "WordWrap", $iWordWrap );
01419     }
01420 
01428     public function setUseInlineImages( $blUseImages = null )
01429     {
01430         $this->_blInlineImgEmail = $blUseImages;
01431     }
01432 
01443     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01444     {
01445         $sFullPath = $sAttPath . $sAttFile;
01446 
01447         $this->_aAttachments[] = array( $sFullPath, $sAttFile, $sEncoding, $sType );
01448 
01449         try {
01450              $blResult = parent::addAttachment( $sFullPath, $sAttFile, $sEncoding, $sType );
01451         } catch( Exception $oEx ) {
01452             return false;
01453         }
01454 
01455         return $blResult;
01456     }
01457 
01469     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01470     {
01471         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01472         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01473     }
01474 
01480     public function getAttachments()
01481     {
01482         return $this->_aAttachments;
01483     }
01484 
01490     public function clearAttachments()
01491     {
01492         $this->_aAttachments = array();
01493         return parent::clearAttachments();
01494     }
01495 
01505     public function headerLine($sName, $sValue)
01506     {
01507         if (stripos($sName, 'X-') !== false) {
01508             return;
01509         }
01510         return parent::headerLine($sName, $sValue);
01511     }
01512 
01518     protected function _getUseInlineImages()
01519     {
01520         return $this->_blInlineImgEmail;
01521     }
01522 
01528     protected function _sendMailErrorMsg()
01529     {
01530         // build addresses
01531         $sToAdress  = "";
01532         $sToName    = "";
01533 
01534         $aRecipients = $this->getRecipient();
01535 
01536         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01537 
01538         foreach ( $aRecipients as $aEMail ) {
01539             $sOwnerMessage .= $aEMail[0];
01540             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01541             $sOwnerMessage .= " \n ";
01542         }
01543         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01544 
01545         // shop info
01546         $oShop = $this->_getShop();
01547 
01548         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop !", $sOwnerMessage);
01549 
01550         return $blRet;
01551     }
01552 
01562     protected function _addUserInfoOrderEMail( $oOrder )
01563     {
01564         return $oOrder;
01565     }
01566 
01576     protected function _addUserRegisterEmail( $oUser )
01577     {
01578         return $oUser;
01579     }
01580 
01590     protected function _addForgotPwdEmail( $oShop )
01591     {
01592         return $oShop;
01593     }
01594 
01604     protected function _addNewsletterDbOptInMail( $oUser )
01605     {
01606         return $oUser;
01607     }
01608 
01614     protected function _clearMailer()
01615     {
01616         $this->clearAllRecipients();
01617         $this->clearReplyTos();
01618         $this->clearAttachments();
01619 
01620         //workaround for phpmailer as it doesn't cleanup as it should
01621         $this->error_count = 0;
01622         $this->ErrorInfo   = '';
01623     }
01624 
01632     protected function _setMailParams( $oShop = null )
01633     {
01634         $this->_clearMailer();
01635 
01636         if ( !$oShop ) {
01637             $oShop = $this->_getShop();
01638         }
01639 
01640         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01641 
01642         $this->setSmtp( $oShop );
01643     }
01644 
01653     protected function _getShop( $iLangId = null )
01654     {
01655         $myConfig = $this->getConfig();
01656         if ( !isset($iLangId) ) {
01657             $iLangId = 0;
01658             $iActShopLang = $myConfig->getActiveShop()->getLanguage();
01659             if ( isset($iActShopLang) && $iActShopLang != $iLangId ) {
01660                 $iLangId = $iActShopLang;
01661             }
01662         }
01663         if ( isset($this->_oShop) && $this->_oShop ) {
01664             // if oShop already setted and reqesting oShop with same language as current oShop,
01665             // or wihtout lang param, return oShop object
01666             if ( isset($iLangId) && $iLangId == $this->_oShop->getLanguage() ) {
01667                 return $this->_oShop;
01668             }
01669         }
01670 
01671         $this->_oShop = oxNew( 'oxshop' );
01672 
01673         $iLangId = oxLang::getInstance()->validateLanguage( $iLangId );
01674 
01675         $this->_oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01676 
01677         $oView = $myConfig->getActiveView();
01678         $this->_oShop = $oView->addGlobalParams( $this->_oShop );
01679 
01680         return $this->_oShop;
01681     }
01682 
01691     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01692     {
01693         $this->set( "SMTPAuth", true );
01694         $this->set( "Username", $sUserName );
01695         $this->set( "Password", $sUserPassword );
01696     }
01697 
01705     protected function _setSmtpDebug( $blDebug = null )
01706     {
01707         $this->set( "SMTPDebug", $blDebug );
01708     }
01709 
01715     protected function _setMailerPluginDir()
01716     {
01717         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
01718     }
01719 
01726     protected function _makeOutputProcessing()
01727     {
01728         $oOutput = oxNew( "oxoutput" );
01729         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01730         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01731         $oOutput->processEmail( $this );
01732     }
01733 
01739     protected function _sendMail()
01740     {
01741         try {
01742              $blResult = parent::send();
01743         } catch( Exception $oEx ) {
01744             return false;
01745         }
01746 
01747         return $blResult;
01748     }
01749 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5