OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxemail.php
Go to the documentation of this file.
1 <?php
5 require oxRegistry::getConfig()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
6 
7 
13 class oxEmail extends PHPMailer
14 {
20  public $SMTP_PORT = 25;
21 
27  protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
28 
34  protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
35 
41  protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
42 
48  protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
49 
55  protected $_sSuggestTemplate = "email/html/suggest.tpl";
56 
62  protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
63 
69  protected $_sInviteTemplate = "email/html/invite.tpl";
70 
76  protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
77 
83  protected $_sSenedNowTemplate = "email/html/ordershipped.tpl";
84 
90  protected $_sSenedNowTemplatePlain = "email/plain/ordershipped.tpl";
91 
97  protected $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
98 
104  protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
105 
111  protected $_sWishListTemplate = "email/html/wishlist.tpl";
112 
118  protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
119 
125  protected $_sRegisterTemplate = "email/html/register.tpl";
126 
132  protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
133 
139  protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
140 
146  protected $_sOrderUserTemplate = "email/html/order_cust.tpl";
147 
153  protected $_sOrderUserPlainTemplate = "email/plain/order_cust.tpl";
154 
160  protected $_sOrderOwnerTemplate = "email/html/order_owner.tpl";
161 
167  protected $_sOrderOwnerPlainTemplate = "email/plain/order_owner.tpl";
168 
169  // #586A - additional templates for more customizable subjects
170 
176  protected $_sOrderUserSubjectTemplate = "email/html/order_cust_subj.tpl";
177 
183  protected $_sOrderOwnerSubjectTemplate = "email/html/order_owner_subj.tpl";
184 
190  protected $_sOwnerPricealarmTemplate = "email/html/pricealarm_owner.tpl";
191 
197  protected $_sPricealamrCustomerTemplate = "email_pricealarm_customer.tpl";
198 
204  protected $_aShops = array();
205 
211  protected $_blInlineImgEmail = null;
212 
218  protected $_aRecipients = array();
219 
225  protected $_aReplies = array();
226 
232  protected $_aAttachments = array();
233 
239  protected $_oSmarty = null;
240 
246  protected $_aViewData = array();
247 
253  protected $_oShop = null;
254 
260  protected $_sCharSet = null;
261 
265  public function __construct()
266  {
267  //enabling exception handling in phpmailer class
268  parent::__construct( true );
269 
270  $myConfig = $this->getConfig();
271 
272  $this->_setMailerPluginDir();
273  $this->setSmtp();
274 
275  $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
276  $this->setMailWordWrap( 100 );
277 
278  $this->isHtml( true );
279  $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
280 
281  $this->_getSmarty();
282  }
283 
295  public function __call( $sMethod, $aArgs )
296  {
297  if ( defined( 'OXID_PHP_UNIT' ) ) {
298  if ( substr( $sMethod, 0, 4) == "UNIT" ) {
299  $sMethod = str_replace( "UNIT", "_", $sMethod );
300  }
301  if ( method_exists( $this, $sMethod)) {
302  return call_user_func_array( array( & $this, $sMethod ), $aArgs );
303  }
304  }
305 
306  throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
307  }
308 
314  public function getConfig()
315  {
316  if ( $this->_oConfig == null ) {
317  $this->_oConfig = oxRegistry::getConfig();
318  }
319 
320  return $this->_oConfig;
321  }
322 
330  public function setConfig( $oConfig )
331  {
332  $this->_oConfig = $oConfig;
333  }
334 
335 
341  protected function _getSmarty()
342  {
343  if ( $this->_oSmarty === null ) {
344  $this->_oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
345  }
346 
347  //setting default view
348  $this->_oSmarty->assign( "oEmailView", $this );
349 
350  return $this->_oSmarty;
351  }
352 
360  public function send()
361  {
362  // if no recipients found, skipping sending
363  if ( count( $this->getRecipient() ) < 1 ) {
364  return false;
365  }
366 
367  $myConfig = $this->getConfig();
368  $this->setCharSet();
369 
370  if ( $this->_getUseInlineImages() ) {
371  $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
372  $myConfig->getImageDir(), $myConfig->getPictureDir(false));
373  }
374 
375  $this->_makeOutputProcessing();
376 
377  // try to send mail via SMTP
378  if ( $this->getMailer() == 'smtp' ) {
379  $blRet = $this->_sendMail();
380 
381  // if sending failed, try to send via mail()
382  if ( !$blRet ) {
383  // failed sending via SMTP, sending notification to shop owner
384  $this->_sendMailErrorMsg();
385 
386  // trying to send using standard mailer
387  $this->setMailer( 'mail' );
388  $blRet = $this->_sendMail();
389  }
390  } else {
391  // sending mail via mail()
392  $this->setMailer( 'mail' );
393  $blRet = $this->_sendMail();
394  }
395 
396  if ( !$blRet ) {
397  // failed sending, giving up, trying to send notification to shop owner
398  $this->_sendMailErrorMsg();
399  }
400 
401  return $blRet;
402  }
403 
412  protected function _setSmtpProtocol($sUrl)
413  {
414  $sProtocol = '';
415  $sSmtpHost = $sUrl;
416  $aMatch = array();
417  if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
418  if ($aMatch[1]) {
419  if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
420  $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
421  } else {
422  $sProtocol = $aMatch[1];
423  }
424  }
425  $sSmtpHost = $aMatch[2];
426  }
427 
428  return $sProtocol.$sSmtpHost;
429  }
430 
438  public function setSmtp( $oShop = null )
439  {
440  $myConfig = $this->getConfig();
441  $oShop = ( $oShop ) ? $oShop : $this->_getShop();
442 
443  $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
444 
445  if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
446  $this->setMailer( "mail" );
447  return;
448  }
449 
450  $this->setHost( $sSmtpUrl );
451  $this->setMailer( "smtp" );
452 
453  if ( $oShop->oxshops__oxsmtpuser->value ) {
454  $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
455  }
456 
457  if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
458  $this->_setSmtpDebug( true );
459  }
460  }
461 
469  protected function _isValidSmtpHost( $sSmtpHost )
470  {
471  $blIsSmtp = false;
472  if ( $sSmtpHost ) {
473  $sSmtpPort = $this->SMTP_PORT;
474  $aMatch = array();
475  if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
476  $sSmtpHost = $aMatch[1];
477  $sSmtpPort = (int)$aMatch[3];
478  if (!$sSmtpPort) {
479  $sSmtpPort = $this->SMTP_PORT;
480  }
481  }
482  if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
483  // closing connection ..
484  fclose( $rHandle );
485  }
486  }
487 
488  return $blIsSmtp;
489  }
490 
500  public function sendOrderEmailToUser( $oOrder, $sSubject = null )
501  {
502  $myConfig = $this->getConfig();
503 
504  // add user defined stuff if there is any
505  $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
506 
507  $oShop = $this->_getShop();
508  $this->_setMailParams( $oShop );
509 
510  $oUser = $oOrder->getOrderUser();
511  $this->setUser( $oUser );
512 
513  // create messages
514  $oSmarty = $this->_getSmarty();
515  $this->setViewData( "order", $oOrder);
516 
517  if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
518  $this->setViewData( "blShowReviewLink", true );
519  }
520 
521  // Process view data array through oxOutput processor
522  $this->_processViewArray();
523 
524  $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
525  $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
526 
527  // #586A
528  if ( $sSubject === null ) {
529  if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
530  $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
531  } else {
532  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
533  }
534  }
535 
536  $this->setSubject( $sSubject );
537 
538  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
539 
540  $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
541  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
542 
543  $blSuccess = $this->send();
544 
545  return $blSuccess;
546  }
547 
557  public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
558  {
559  $myConfig = $this->getConfig();
560 
561  $oShop = $this->_getShop();
562 
563  // cleanup
564  $this->_clearMailer();
565 
566  // add user defined stuff if there is any
567  $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
568 
569  $oUser = $oOrder->getOrderUser();
570  $this->setUser( $oUser );
571 
572  // send confirmation to shop owner
573  // send not pretending from order user, as different email domain rise spam filters
574  $this->setFrom( $oShop->oxshops__oxowneremail->value );
575 
576  $oLang = oxRegistry::getLang();
577  $iOrderLang = $oLang->getObjectTplLanguage();
578 
579  // if running shop language is different from admin lang. set in config
580  // we have to load shop in config language
581  if ( $oShop->getLanguage() != $iOrderLang ) {
582  $oShop = $this->_getShop( $iOrderLang );
583  }
584 
585  $this->setSmtp( $oShop );
586 
587  // create messages
588  $oSmarty = $this->_getSmarty();
589  $this->setViewData( "order", $oOrder );
590 
591  // Process view data array through oxoutput processor
592  $this->_processViewArray();
593 
594  $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
595  $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
596 
597  //Sets subject to email
598  // #586A
599  if ( $sSubject === null ) {
600  if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
601  $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
602  } else {
603  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
604  }
605  }
606 
607  $this->setSubject( $sSubject );
608  $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
609 
610  if ( $oUser->oxuser__oxusername->value != "admin" ) {
611  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
612  $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
613  }
614 
615  $blSuccess = $this->send();
616 
617  // add user history
618  $oRemark = oxNew( "oxremark" );
619  $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
620  $oRemark->oxremark__oxparentid = new oxField($oUser->getId(), oxField::T_RAW);
621  $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
622  $oRemark->save();
623 
624 
625  if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
626  oxRegistry::getUtils()->showMessageAndExit( "" );
627  }
628 
629  return $blSuccess;
630  }
631 
641  public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
642  {
643  // setting content ident
644 
645  $this->setViewData( "contentident", "oxregisteraltemail" );
646  $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
647 
648  // sending email
649  return $this->sendRegisterEmail( $oUser, $sSubject );
650  }
651 
661  public function sendRegisterEmail( $oUser, $sSubject = null )
662  {
663  // add user defined stuff if there is any
664  $oUser = $this->_addUserRegisterEmail( $oUser );
665 
666  // shop info
667  $oShop = $this->_getShop();
668 
669  //set mail params (from, fromName, smtp )
670  $this->_setMailParams( $oShop );
671 
672  // create messages
673  $oSmarty = $this->_getSmarty();
674  $this->setUser( $oUser );
675 
676  // Process view data array through oxOutput processor
677  $this->_processViewArray();
678 
679  $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
680  $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
681 
682  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
683 
684  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
685 
686  $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
687  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
688 
689  return $this->send();
690  }
691 
701  public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
702  {
703  $myConfig = $this->getConfig();
704  $oDb = oxDb::getDb();
705 
706  // shop info
707  $oShop = $this->_getShop();
708 
709  // add user defined stuff if there is any
710  $oShop = $this->_addForgotPwdEmail( $oShop );
711 
712  //set mail params (from, fromName, smtp)
713  $this->_setMailParams( $oShop );
714 
715  // user
716  $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
717  $sOrder = "";
718  if ( $myConfig->getConfigParam( 'blMallUsers' )) {
719  $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
720  } else {
721  $sWhere .= " and oxshopid = '".$oShop->getId()."'";
722  }
723 
724  $sSelect = "select oxid from oxuser where $sWhere $sOrder";
725  if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
726 
727  $oUser = oxNew( 'oxuser' );
728  if ( $oUser->load($sOxId) ) {
729  // create messages
730  $oSmarty = $this->_getSmarty();
731  $this->setUser( $oUser );
732 
733  // Process view data array through oxoutput processor
734  $this->_processViewArray();
735 
736  $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
737 
738  $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
739 
740  //sets subject of email
741  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
742 
743  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
744 
745  $this->setRecipient( $sEmailAddress, $sFullName );
746  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
747 
748  if ( !$this->send() ) {
749  return -1; // failed to send
750  }
751  return true; // success
752  }
753  }
754 
755  return false; // user with this email not found
756  }
757 
768  public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
769  {
770 
771  // shop info
772  $oShop = $this->_getShop();
773 
774  //set mail params (from, fromName, smtp)
775  $this->_setMailParams( $oShop );
776 
777  $this->setBody( $sMessage );
778  $this->setSubject( $sSubject );
779 
780  $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
781  $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
782  $this->setReplyTo( $sEmailAddress, "" );
783 
784  return $this->send();
785  }
786 
796  public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
797  {
798  $oLang = oxRegistry::getLang();
799 
800  // add user defined stuff if there is any
801  $oUser = $this->_addNewsletterDbOptInMail( $oUser );
802 
803  // shop info
804  $oShop = $this->_getShop();
805 
806  //set mail params (from, fromName, smtp)
807  $this->_setMailParams( $oShop );
808 
809  // create messages
810  $oSmarty = $this->_getSmarty();
811  $sConfirmCode = md5($oUser->oxuser__oxusername->value.$oUser->oxuser__oxpasssalt->value);
812  $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value, $sConfirmCode ) );
813  $this->setUser( $oUser );
814 
815  // Process view data array through oxOutput processor
816  $this->_processViewArray();
817 
818  $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
819  $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
820  $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxRegistry::getLang()->translateString("NEWSLETTER") . " " . $oShop->oxshops__oxname->getRawValue() );
821 
822  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
823 
824  $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
825  $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
826  $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
827 
828  return $this->send();
829  }
830 
839  protected function _getNewsSubsLink( $sId, $sConfirmCode = null )
840  {
841  $myConfig = $this->getConfig();
842  $iActShopLang = $myConfig->getActiveShop()->getLanguage();
843 
844  $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
845  $sUrl.= '&amp;lang='.$iActShopLang;
846  $sUrl.= ( $sConfirmCode ) ? '&amp;confirm='.$sConfirmCode : "";
847  return $sUrl;
848  }
849 
860  public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
861  {
862  // shop info
863  $oShop = $this->_getShop();
864 
865  //set mail params (from, fromName, smtp)
866  $this->_setMailParams( $oShop );
867 
868  $sBody = $oNewsLetter->getHtmlText();
869 
870  if ( !empty($sBody) ) {
871  $this->setBody( $sBody );
872  $this->setAltBody( $oNewsLetter->getPlainText() );
873  } else {
874  $this->isHtml( false );
875  $this->setBody( $oNewsLetter->getPlainText() );
876  }
877 
878  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
879 
880  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
881  $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
882  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
883 
884  return $this->send();
885  }
886 
896  public function sendSuggestMail( $oParams, $oProduct )
897  {
898  $myConfig = $this->getConfig();
899 
900  //sets language of shop
901  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
902 
903  // shop info
904  $oShop = $this->_getShop( $iCurrLang );
905 
906  //sets language to article
907  if ( $oProduct->getLanguage() != $iCurrLang ) {
908  $oProduct->setLanguage( $iCurrLang );
909  $oProduct->load( $oProduct->getId() );
910  }
911 
912  // mailer stuff
913  // send not pretending from suggesting user, as different email domain rise spam filters
914  $this->setFrom( $oShop->oxshops__oxinfoemail->value );
915  $this->setSMTP();
916 
917  // create messages
918  $oSmarty = $this->_getSmarty();
919  $this->setViewData( "product", $oProduct );
920  $this->setUser( $oParams );
921 
922  $sArticleUrl = $oProduct->getLink();
923 
924  //setting recommended user id
925  if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
926  $sArticleUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sArticleUrl );
927  $sArticleUrl .= "su=" . $oActiveUser->getId();
928  }
929 
930  $this->setViewData( "sArticleUrl", $sArticleUrl );
931 
932  // Process view data array through oxOutput processor
933  $this->_processViewArray();
934 
935  $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
936  $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
937  $this->setSubject( $oParams->send_subject );
938 
939  $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
940  $this->setReplyTo( $oParams->send_email, $oParams->send_name );
941 
942  return $this->send();
943  }
944 
953  public function sendInviteMail( $oParams )
954  {
955  $myConfig = $this->getConfig();
956 
957  //sets language of shop
958  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
959 
960  // shop info
961  $oShop = $this->_getShop( $iCurrLang );
962 
963  // mailer stuff
964  $this->setFrom( $oParams->send_email, $oParams->send_name );
965  $this->setSMTP();
966 
967  // create messages
968  $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
969  $this->setUser( $oParams );
970 
971  $sHomeUrl = $this->getViewConfig()->getHomeLink();
972 
973  //setting recommended user id
974  if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
975  $sHomeUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
976  $sHomeUrl .= "su=" . $oActiveUser->getId();
977  }
978 
979  if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0 ) {
980  foreach ( $oParams->rec_email as $sEmail ) {
981  if ( !empty( $sEmail ) ) {
982  $sRegisterUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
983  //setting recipient user email
984  $sRegisterUrl .= "re=" . md5($sEmail);
985  $this->setViewData( "sHomeUrl", $sRegisterUrl );
986 
987  // Process view data array through oxoutput processor
988  $this->_processViewArray();
989 
990  $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
991 
992  $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
993  $this->setSubject( $oParams->send_subject );
994 
995  $this->setRecipient( $sEmail );
996  $this->setReplyTo( $oParams->send_email, $oParams->send_name );
997  $this->send();
998  $this->clearAllRecipients();
999  }
1000  }
1001  return true;
1002  }
1003 
1004  return false;
1005  }
1006 
1016  public function sendSendedNowMail( $oOrder, $sSubject = null )
1017  {
1018  $myConfig = $this->getConfig();
1019 
1020  $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
1021 
1022  // shop info
1023  $oShop = $this->_getShop( $iOrderLang );
1024 
1025  //set mail params (from, fromName, smtp)
1026  $this->_setMailParams( $oShop );
1027 
1028  //create messages
1029  $oLang = oxRegistry::getLang();
1030  $oSmarty = $this->_getSmarty();
1031  $this->setViewData( "order", $oOrder );
1032  $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
1033 
1034  if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
1035  $this->setViewData( "blShowReviewLink", true );
1036  $oUser = oxNew( 'oxuser' );
1037  $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
1038  }
1039 
1040  // Process view data array through oxoutput processor
1041  $this->_processViewArray();
1042 
1043  // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1044  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1045  //V send email in order language
1046  $iOldTplLang = $oLang->getTplLanguage();
1047  $iOldBaseLang = $oLang->getTplLanguage();
1048  $oLang->setTplLanguage( $iOrderLang );
1049  $oLang->setBaseLanguage( $iOrderLang );
1050 
1051  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1052  // force non admin to get correct paths (tpl, img)
1053  $myConfig->setAdminMode( false );
1054  $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
1055  $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
1056  $myConfig->setAdminMode( true );
1057  $oLang->setTplLanguage( $iOldTplLang );
1058  $oLang->setBaseLanguage( $iOldBaseLang );
1059  // set it back
1060  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
1061 
1062  //Sets subject to email
1063  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
1064 
1065  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1066 
1067  $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
1068  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
1069 
1070  return $this->send();
1071  }
1072 
1082  public function sendDownloadLinksMail( $oOrder, $sSubject = null )
1083  {
1084  $myConfig = $this->getConfig();
1085 
1086  $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
1087 
1088  // shop info
1089  $oShop = $this->_getShop( $iOrderLang );
1090 
1091  //set mail params (from, fromName, smtp)
1092  $this->_setMailParams( $oShop );
1093 
1094  //create messages
1095  $oLang = oxRegistry::getLang();
1096  $oSmarty = $this->_getSmarty();
1097  $this->setViewData( "order", $oOrder );
1098  $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
1099 
1100  $oUser = oxNew( 'oxuser' );
1101  $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
1102 
1103  // Process view data array through oxoutput processor
1104  $this->_processViewArray();
1105 
1106  // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1107  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1108  //V send email in order language
1109  $iOldTplLang = $oLang->getTplLanguage();
1110  $iOldBaseLang = $oLang->getTplLanguage();
1111  $oLang->setTplLanguage( $iOrderLang );
1112  $oLang->setBaseLanguage( $iOrderLang );
1113 
1114  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1115  // force non admin to get correct paths (tpl, img)
1116  $myConfig->setAdminMode( false );
1117  $this->setBody( $oSmarty->fetch( $this->_sSendDownloadsTemplate ) );
1118  $this->setAltBody( $oSmarty->fetch( $this->_sSendDownloadsTemplatePlain ) );
1119  $myConfig->setAdminMode( true );
1120  $oLang->setTplLanguage( $iOldTplLang );
1121  $oLang->setBaseLanguage( $iOldBaseLang );
1122  // set it back
1123  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
1124 
1125  //Sets subject to email
1126  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString("DOWNLOAD_LINKS", null, false) );
1127 
1128  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1129 
1130  $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
1131  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
1132 
1133  return $this->send();
1134  }
1135 
1150  public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
1151  {
1152  // shop info
1153  $oShop = $this->_getShop();
1154 
1155  //set mail params (from, fromName, smtp)
1156  $this->_setMailParams( $oShop );
1157 
1158  $this->setBody( $sMessage );
1159  $this->setSubject( $sSubject );
1160 
1161  $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
1162  $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
1163 
1164  $this->setFrom( $sEmailAddress, "" );
1165  $this->setReplyTo( $sEmailAddress, "" );
1166 
1167  //attaching files
1168  $blAttashSucc = true;
1169  $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
1170  foreach ( $aAttFiles as $iNum => $sAttFile ) {
1171  $sFullPath = $sAttPath . $sAttFile;
1172  if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
1173  $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
1174  } else {
1175  $blAttashSucc = false;
1176  $aError[] = array( 5, $sAttFile ); //"Error: backup file $sAttFile not found";
1177  }
1178  }
1179 
1180  if ( !$blAttashSucc ) {
1181  $aError[] = array( 4, "" ); //"Error: backup files was not sent to email ...";
1182  $this->clearAttachments();
1183  return false;
1184  }
1185 
1186  $aStatus[] = 3; //"Mailing backup files ...";
1187  $blSend = $this->send();
1188  $this->clearAttachments();
1189 
1190  return $blSend;
1191  }
1192 
1203  public function sendEmail( $sTo, $sSubject, $sBody )
1204  {
1205  //set mail params (from, fromName, smtp)
1206  $this->_setMailParams();
1207 
1208  if ( is_array($sTo) ) {
1209  foreach ($sTo as $sAddress) {
1210  $this->setRecipient( $sAddress, "" );
1211  $this->setReplyTo( $sAddress, "" );
1212  }
1213  } else {
1214  $this->setRecipient( $sTo, "" );
1215  $this->setReplyTo( $sTo, "" );
1216  }
1217 
1218  //may be changed later
1219  $this->isHtml( false );
1220 
1221  $this->setSubject( $sSubject );
1222  $this->setBody( $sBody );
1223 
1224  return $this->send();
1225  }
1226 
1235  public function sendStockReminder( $aBasketContents, $sSubject = null )
1236  {
1237  $blSend = false;
1238 
1239  $oArticleList = oxNew( "oxarticlelist" );
1240  $oArticleList->loadStockRemindProducts( $aBasketContents );
1241 
1242  // nothing to remind?
1243  if ( $oArticleList->count() ) {
1244  $oShop = $this->_getShop();
1245 
1246  //set mail params (from, fromName, smtp... )
1247  $this->_setMailParams( $oShop );
1248  $oLang = oxRegistry::getLang();
1249 
1250  $oSmarty = $this->_getSmarty();
1251  $this->setViewData( "articles", $oArticleList );
1252 
1253  // Process view data array through oxOutput processor
1254  $this->_processViewArray();
1255 
1256  $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
1257  $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
1258  $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
1259  $this->setAltBody( "" );
1260  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'STOCK_LOW' ) );
1261 
1262  $blSend = $this->send();
1263  }
1264 
1265  return $blSend;
1266  }
1267 
1276  public function sendWishlistMail( $oParams )
1277  {
1278  $myConfig = $this->getConfig();
1279 
1280  $this->_clearMailer();
1281 
1282  // shop info
1283  $oShop = $this->_getShop();
1284 
1285  // mailer stuff
1286  $this->setFrom( $oParams->send_email, $oParams->send_name );
1287  $this->setSMTP();
1288 
1289  // create messages
1290  $oSmarty = $this->_getSmarty();
1291  $this->setUser( $oParams );
1292 
1293  // Process view data array through oxoutput processor
1294  $this->_processViewArray();
1295 
1296  $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
1297  $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
1298  $this->setSubject( $oParams->send_subject );
1299 
1300  $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
1301  $this->setReplyTo( $oParams->send_email, $oParams->send_name );
1302 
1303  return $this->send();
1304  }
1305 
1316  public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
1317  {
1318  $this->_clearMailer();
1319  $oShop = $this->_getShop();
1320 
1321  //set mail params (from, fromName, smtp)
1322  $this->_setMailParams( $oShop );
1323 
1324  $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
1325 
1326  $oArticle = oxNew( "oxarticle" );
1327  //$oArticle->setSkipAbPrice( true );
1328  $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
1329  $oLang = oxRegistry::getLang();
1330 
1331  // create messages
1332  $oSmarty = $this->_getSmarty();
1333  $this->setViewData( "product", $oArticle );
1334  $this->setViewData( "email", $aParams['email']);
1335  $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
1336 
1337  // Process view data array through oxOutput processor
1338  $this->_processViewArray();
1339 
1340  $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
1341  $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'PRICE_ALERT_FOR_PRODUCT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
1342  $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
1343  $this->setFrom( $aParams['email'], "" );
1344  $this->setReplyTo( $aParams['email'], "" );
1345 
1346  return $this->send();
1347  }
1348 
1360  public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
1361  {
1362  $this->_clearMailer();
1363 
1364  $oShop = $this->_getShop();
1365 
1366  if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
1367  $oShop = oxNew( "oxshop" );
1368  $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
1369  $this->setShop( $oShop );
1370  }
1371 
1372  //set mail params (from, fromName, smtp)
1373  $this->_setMailParams( $oShop );
1374 
1375  // create messages
1376  $oSmarty = $this->_getSmarty();
1377 
1378  $this->setViewData( "product", $oAlarm->getArticle() );
1379  $this->setViewData( "oPriceAlarm", $oAlarm );
1380  $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
1381  $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
1382 
1383  // Process view data array through oxoutput processor
1384  $this->_processViewArray();
1385 
1386  $this->setRecipient( $sRecipient, $sRecipient );
1387  $this->setSubject( $oShop->oxshops__oxname->value );
1388 
1389  if ( $sBody === null ) {
1390  $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
1391  }
1392 
1393  $this->setBody( $sBody );
1394 
1395  $this->addAddress( $sRecipient, $sRecipient );
1396  $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
1397 
1398  if ( $sReturnMailBody ) {
1399  return $this->getBody();
1400  } else {
1401  return $this->send();
1402  }
1403  }
1404 
1416  protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
1417  {
1418  $sBody = $this->getBody();
1419  if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
1420 
1421  $oFileUtils = oxRegistry::get("oxUtilsFile");
1422  $blReSetBody = false;
1423 
1424  // preparing imput
1425  $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
1426  $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
1427  $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
1428 
1429  if (is_array($matches) && count($matches)) {
1430  $aImageCache = array();
1431  $myUtils = oxRegistry::getUtils();
1432  $myUtilsObject = oxUtilsObject::getInstance();
1433  $oImgGenerator = oxNew( "oxDynImgGenerator" );
1434 
1435  foreach ($matches as $aImage) {
1436 
1437  $image = $aImage[1];
1438  $sFileName = '';
1439  if ( strpos( $image, $sDynImageDir ) === 0 ) {
1440  $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
1441  } elseif ( strpos( $image, $sImageDir ) === 0 ) {
1442  $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
1443  } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
1444  $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
1445  }
1446 
1447  if ( $sFileName && !@is_readable( $sFileName ) ) {
1448  $sFileName = $oImgGenerator->getImagePath( $sFileName );
1449  }
1450 
1451  if ( $sFileName ) {
1452  $sCId = '';
1453  if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
1454  $sCId = $aImageCache[$sFileName];
1455  } else {
1456  $sCId = $myUtilsObject->generateUID();
1457  $sMIME = $myUtils->oxMimeContentType($sFileName);
1458  if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
1459  if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
1460  $aImageCache[$sFileName] = $sCId;
1461  } else {
1462  $sCId = '';
1463  }
1464  }
1465  }
1466  if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
1467  if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
1468  $sBody = str_replace($aImage[0], $sReplTag, $sBody );
1469  $blReSetBody = true;
1470  }
1471  }
1472  }
1473  }
1474  }
1475 
1476  if ( $blReSetBody ) {
1477  $this->setBody( $sBody );
1478  }
1479  }
1480  }
1481 
1489  public function setSubject( $sSubject = null )
1490  {
1491  // A. HTML entities in subjects must be replaced
1492  $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
1493 
1494  $this->set( "Subject", $sSubject );
1495  }
1496 
1502  public function getSubject()
1503  {
1504  return $this->Subject;
1505  }
1506 
1516  public function setBody( $sBody = null, $blClearSid = true )
1517  {
1518  if ( $blClearSid ) {
1519  $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
1520  }
1521 
1522  $this->set( "Body", $sBody );
1523  }
1524 
1530  public function getBody()
1531  {
1532  return $this->Body;
1533  }
1534 
1544  public function setAltBody( $sAltBody = null, $blClearSid = true )
1545  {
1546  if ( $blClearSid ) {
1547  $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
1548  }
1549 
1550  // A. alt body is used for plain text emails so we should eliminate HTML entities
1551  $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
1552 
1553  $this->set( "AltBody", $sAltBody );
1554  }
1555 
1561  public function getAltBody()
1562  {
1563  return $this->AltBody;
1564  }
1565 
1574  public function setRecipient( $sAddress = null, $sName = null )
1575  {
1576  try {
1577  parent::AddAddress( $sAddress, $sName );
1578 
1579  // copying values as original class does not allow to access recipients array
1580  $this->_aRecipients[] = array( $sAddress, $sName );
1581  } catch( Exception $oEx ) {
1582  }
1583  }
1584 
1592  public function getRecipient()
1593  {
1594  return $this->_aRecipients;
1595  }
1596 
1603  public function clearAllRecipients()
1604  {
1605  $this->_aRecipients = array();
1607  }
1608 
1620  public function setReplyTo( $sEmail = null, $sName = null )
1621  {
1622  if ( !oxRegistry::getUtils()->isValidEmail( $sEmail ) ) {
1623  $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
1624  }
1625 
1626  $this->_aReplies[] = array( $sEmail, $sName );
1627 
1628  try {
1629  parent::addReplyTo( $sEmail, $sName );
1630  } catch( Exception $oEx ) {
1631  }
1632  }
1633 
1639  public function getReplyTo()
1640  {
1641  return $this->_aReplies;
1642  }
1643 
1649  public function clearReplyTos()
1650  {
1651  $this->_aReplies = array();
1653  }
1654 
1663  public function setFrom( $sFromAddress, $sFromName = null )
1664  {
1665  // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
1666  // this is simple but must work
1667  // dodger Task #1532 field "From" in emails from shops
1668  $sFromAddress = substr($sFromAddress, 0, 150);
1669  $sFromName = substr($sFromName, 0, 150);
1670 
1671  try {
1672  parent::setFrom( $sFromAddress, $sFromName );
1673  } catch( Exception $oEx ) {
1674  }
1675  }
1676 
1682  public function getFrom()
1683  {
1684  return $this->From;
1685  }
1686 
1692  public function getFromName()
1693  {
1694  return $this->FromName;
1695  }
1696 
1705  public function setCharSet( $sCharSet = null )
1706  {
1707  if ( $sCharSet ) {
1708  $this->_sCharSet = $sCharSet;
1709  } else {
1710  $this->_sCharSet = oxRegistry::getLang()->translateString( "charset" );
1711  }
1712  $this->set( "CharSet", $this->_sCharSet );
1713  }
1714 
1722  public function setMailer( $sMailer = null )
1723  {
1724  $this->set( "Mailer", $sMailer );
1725  }
1726 
1732  public function getMailer()
1733  {
1734  return $this->Mailer;
1735  }
1736 
1744  public function setHost( $sHost = null )
1745  {
1746  $this->set( "Host", $sHost );
1747  }
1748 
1754  public function getErrorInfo()
1755  {
1756  return $this->ErrorInfo;
1757  }
1758 
1767  public function setMailWordWrap( $iWordWrap = null )
1768  {
1769  $this->set( "WordWrap", $iWordWrap );
1770  }
1771 
1779  public function setUseInlineImages( $blUseImages = null )
1780  {
1781  $this->_blInlineImgEmail = $blUseImages;
1782  }
1783 
1794  public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
1795  {
1796  $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
1797  $blResult = false;
1798 
1799  try {
1800  $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
1801  } catch( Exception $oEx ) {
1802  }
1803 
1804  return $blResult;
1805  }
1806 
1818  public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
1819  {
1820  $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
1821  return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
1822  }
1823 
1829  public function getAttachments()
1830  {
1831  return $this->_aAttachments;
1832  }
1833 
1839  public function clearAttachments()
1840  {
1841  $this->_aAttachments = array();
1842  return parent::clearAttachments();
1843  }
1844 
1854  public function headerLine($sName, $sValue)
1855  {
1856  if (stripos($sName, 'X-') !== false) {
1857  return;
1858  }
1859  return parent::headerLine($sName, $sValue);
1860  }
1861 
1867  protected function _getUseInlineImages()
1868  {
1869  return $this->_blInlineImgEmail;
1870  }
1871 
1877  protected function _sendMailErrorMsg()
1878  {
1879  // build addresses
1880  $aRecipients = $this->getRecipient();
1881 
1882  $sOwnerMessage = "Error sending eMail(". $this->getSubject().") to: \n\n";
1883 
1884  foreach ( $aRecipients as $aEMail ) {
1885  $sOwnerMessage .= $aEMail[0];
1886  $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
1887  $sOwnerMessage .= " \n ";
1888  }
1889  $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
1890 
1891  // shop info
1892  $oShop = $this->_getShop();
1893 
1894  $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
1895 
1896  return $blRet;
1897  }
1898 
1908  protected function _addUserInfoOrderEMail( $oOrder )
1909  {
1910  return $oOrder;
1911  }
1912 
1922  protected function _addUserRegisterEmail( $oUser )
1923  {
1924  return $oUser;
1925  }
1926 
1936  protected function _addForgotPwdEmail( $oShop )
1937  {
1938  return $oShop;
1939  }
1940 
1950  protected function _addNewsletterDbOptInMail( $oUser )
1951  {
1952  return $oUser;
1953  }
1954 
1960  protected function _clearMailer()
1961  {
1962  $this->clearAllRecipients();
1963  $this->clearReplyTos();
1964  $this->clearAttachments();
1965 
1966  //workaround for phpmailer as it doesn't cleanup as it should
1967  $this->error_count = 0;
1968  $this->ErrorInfo = '';
1969  }
1970 
1978  protected function _setMailParams( $oShop = null )
1979  {
1980  $this->_clearMailer();
1981 
1982  if ( !$oShop ) {
1983  $oShop = $this->_getShop();
1984  }
1985 
1986  $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
1987  $this->setSmtp( $oShop );
1988  }
1989 
1999  protected function _getShop( $iLangId = null, $iShopId = null )
2000  {
2001  if ( $iLangId === null && $iShopId === null ) {
2002  if ( isset( $this->_oShop ) ) {
2003  return $this->_oShop;
2004  } else {
2005  return $this->_oShop = $this->getConfig()->getActiveShop();
2006  }
2007  }
2008 
2009  $myConfig = $this->getConfig();
2010 
2011  $oShop = oxNew( 'oxShop' );
2012  if ( $iShopId !== null ) {
2013  $oShop->setShopId($iShopId);
2014  }
2015  if ( $iLangId !== null ) {
2016  $oShop->setLanguage($iLangId);
2017  }
2018  $oShop->load($myConfig->getShopId());
2019 
2020  return $oShop;
2021  }
2022 
2031  protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
2032  {
2033  $this->set( "SMTPAuth", true );
2034  $this->set( "Username", $sUserName );
2035  $this->set( "Password", $sUserPassword );
2036  }
2037 
2045  protected function _setSmtpDebug( $blDebug = null )
2046  {
2047  $this->set( "SMTPDebug", $blDebug );
2048  }
2049 
2055  protected function _setMailerPluginDir()
2056  {
2057  $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
2058  }
2059 
2066  protected function _makeOutputProcessing()
2067  {
2068  $oOutput = oxNew( "oxOutput" );
2069  $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
2070  $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
2071  $oOutput->processEmail( $this );
2072  }
2073 
2079  protected function _sendMail()
2080  {
2081  $blResult = false;
2082  try {
2083  $blResult = parent::send();
2084  } catch( Exception $oException ) {
2085  $oEx = oxNew( "oxException" );
2086  $oEx->setMessage($oException->getMessage());
2087  $oEx->debugOut();
2088  if ( $this->getConfig()->getConfigParam( 'iDebug' ) != 0 ) {
2089  throw $oEx;
2090  }
2091  }
2092  return $blResult;
2093  }
2094 
2095 
2101  protected function _processViewArray()
2102  {
2103  $oSmarty = $this->_getSmarty();
2104  $oOutputProcessor = oxNew( "oxOutput" );
2105 
2106  // processing all view data
2107  foreach ( $this->_aViewData as $sKey => $sValue ) {
2108  $oSmarty->assign( $sKey, $sValue );
2109  }
2110 
2111  // processing assigned smarty variables
2112  $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
2113 
2114  foreach ( $aNewSmartyArray as $key => $val ) {
2115  $oSmarty->assign( $key, $val );
2116  }
2117  }
2118 
2124  public function getCharset()
2125  {
2126  if ( !$this->_sCharSet ) {
2127  return oxRegistry::getLang()->translateString("charset");
2128  } else {
2129  return $this->CharSet;
2130  }
2131  }
2132 
2138  public function getShop()
2139  {
2140  return $this->_getShop();
2141  }
2142 
2150  public function setShop( $oShop )
2151  {
2152  $this->_oShop = $oShop;
2153  }
2154 
2160  public function getViewConfig()
2161  {
2162  return $this->getConfig()->getActiveView()->getViewConfig();
2163  }
2164 
2170  public function getView()
2171  {
2172  return $this->getConfig()->getActiveView();
2173  }
2174 
2180  public function getCurrency()
2181  {
2182  $oConfig = oxRegistry::getConfig();
2183 
2184  return $oConfig->getActShopCurrencyObject();
2185  }
2186 
2195  public function setViewData( $sKey, $sValue )
2196  {
2197  $this->_aViewData[$sKey] = $sValue;
2198  }
2199 
2205  public function getViewData()
2206  {
2207  return $this->_aViewData;
2208  }
2209 
2217  public function getViewDataItem( $sKey )
2218  {
2219  if ( isset($this->_aViewData[$sKey]) ) {
2220  return $this->_aViewData;
2221  }
2222  }
2223 
2231  public function setUser( $oUser)
2232  {
2233  $this->_aViewData["oUser"] = $oUser;
2234  }
2235 
2241  public function getUser()
2242  {
2243  return $this->_aViewData["oUser"];
2244  }
2245 
2253  public function getOrderFileList( $sOrderId )
2254  {
2255  $oOrderList = oxNew('oxOrderFileList');
2256  $oOrderList->loadOrderFiles( $sOrderId );
2257 
2258  if ( count($oOrderList) > 0 ) {
2259  return $oOrderList;
2260  }
2261 
2262  return false;
2263  }
2264 
2265 }