OXID eShop CE  4.9.9
 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 require oxRegistry::getConfig()->getConfigParam('sCoreDir') . "/phpmailer/class.smtp.php";
7 
8 
14 class oxEmail extends PHPMailer
15 {
16 
22  public $SMTP_PORT = 25;
23 
29  protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
30 
36  protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
37 
43  protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
44 
50  protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
51 
57  protected $_sSuggestTemplate = "email/html/suggest.tpl";
58 
64  protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
65 
71  protected $_sInviteTemplate = "email/html/invite.tpl";
72 
78  protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
79 
85  protected $_sSenedNowTemplate = "email/html/ordershipped.tpl";
86 
92  protected $_sSenedNowTemplatePlain = "email/plain/ordershipped.tpl";
93 
99  protected $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
100 
106  protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
107 
113  protected $_sWishListTemplate = "email/html/wishlist.tpl";
114 
120  protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
121 
127  protected $_sRegisterTemplate = "email/html/register.tpl";
128 
134  protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
135 
141  protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
142 
148  protected $_sOrderUserTemplate = "email/html/order_cust.tpl";
149 
155  protected $_sOrderUserPlainTemplate = "email/plain/order_cust.tpl";
156 
162  protected $_sOrderOwnerTemplate = "email/html/order_owner.tpl";
163 
169  protected $_sOrderOwnerPlainTemplate = "email/plain/order_owner.tpl";
170 
171  // #586A - additional templates for more customizable subjects
172 
178  protected $_sOrderUserSubjectTemplate = "email/html/order_cust_subj.tpl";
179 
185  protected $_sOrderOwnerSubjectTemplate = "email/html/order_owner_subj.tpl";
186 
192  protected $_sOwnerPricealarmTemplate = "email/html/pricealarm_owner.tpl";
193 
199  protected $_sPricealamrCustomerTemplate = "email_pricealarm_customer.tpl";
200 
206  protected $_aShops = array();
207 
213  protected $_blInlineImgEmail = null;
214 
220  protected $_aRecipients = array();
221 
227  protected $_aReplies = array();
228 
234  protected $_aAttachments = array();
235 
241  protected $_oSmarty = null;
242 
248  protected $_aViewData = array();
249 
255  protected $_oShop = null;
256 
262  protected $_sCharSet = null;
263 
267  public function __construct()
268  {
269  //enabling exception handling in phpmailer class
270  parent::__construct(true);
271 
272  $myConfig = $this->getConfig();
273 
274  $this->_setMailerPluginDir();
275  $this->setSmtp();
276 
277  $this->setUseInlineImages($myConfig->getConfigParam('blInlineImgEmail'));
278  $this->setMailWordWrap(100);
279 
280  $this->isHtml(true);
281  $this->setLanguage("en", $myConfig->getConfigParam('sShopDir') . "/core/phpmailer/language/");
282 
283  $this->_getSmarty();
284  }
285 
297  public function __call($sMethod, $aArgs)
298  {
299  if (defined('OXID_PHP_UNIT')) {
300  if (substr($sMethod, 0, 4) == "UNIT") {
301  $sMethod = str_replace("UNIT", "_", $sMethod);
302  }
303  if (method_exists($this, $sMethod)) {
304  return call_user_func_array(array(& $this, $sMethod), $aArgs);
305  }
306  }
307 
308  throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")" . PHP_EOL);
309  }
310 
316  public function getConfig()
317  {
318  if ($this->_oConfig == null) {
319  $this->_oConfig = oxRegistry::getConfig();
320  }
321 
322  return $this->_oConfig;
323  }
324 
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(
372  $myConfig->getImageDir(), $myConfig->getImageUrl(false, false), $myConfig->getPictureUrl(null, false),
373  $myConfig->getImageDir(), $myConfig->getPictureDir(false)
374  );
375  }
376 
377  $this->_makeOutputProcessing();
378 
379  // try to send mail via SMTP
380  if ($this->getMailer() == 'smtp') {
381  $blRet = $this->_sendMail();
382 
383  // if sending failed, try to send via mail()
384  if (!$blRet) {
385  // failed sending via SMTP, sending notification to shop owner
386  $this->_sendMailErrorMsg();
387 
388  // trying to send using standard mailer
389  $this->setMailer('mail');
390  $blRet = $this->_sendMail();
391  }
392  } else {
393  // sending mail via mail()
394  $this->setMailer('mail');
395  $blRet = $this->_sendMail();
396  }
397 
398  if (!$blRet) {
399  // failed sending, giving up, trying to send notification to shop owner
400  $this->_sendMailErrorMsg();
401  }
402 
403  return $blRet;
404  }
405 
414  protected function _setSmtpProtocol($sUrl)
415  {
416  $sProtocol = '';
417  $sSmtpHost = $sUrl;
418  $aMatch = array();
419  if (getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch)) {
420  if ($aMatch[1]) {
421  if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
422  $this->set("SMTPSecure", substr($aMatch[1], 0, 3));
423  } else {
424  $sProtocol = $aMatch[1];
425  }
426  }
427  $sSmtpHost = $aMatch[2];
428  }
429 
430  return $sProtocol . $sSmtpHost;
431  }
432 
440  public function setSmtp($oShop = null)
441  {
442  $myConfig = $this->getConfig();
443  $oShop = ($oShop) ? $oShop : $this->_getShop();
444 
445  $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
446 
447  if (!$this->_isValidSmtpHost($sSmtpUrl)) {
448  $this->setMailer("mail");
449 
450  return;
451  }
452 
453  $this->setHost($sSmtpUrl);
454  $this->setMailer("smtp");
455 
456  if ($oShop->oxshops__oxsmtpuser->value) {
457  $this->_setSmtpAuthInfo($oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value);
458  }
459 
460  if ($myConfig->getConfigParam('iDebug') == 6) {
461  $this->_setSmtpDebug(true);
462  }
463  }
464 
472  protected function _isValidSmtpHost($sSmtpHost)
473  {
474  $blIsSmtp = false;
475  if ($sSmtpHost) {
476  $sSmtpPort = $this->SMTP_PORT;
477  $aMatch = array();
478  if (getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
479  $sSmtpHost = $aMatch[1];
480  $sSmtpPort = (int) $aMatch[3];
481  if (!$sSmtpPort) {
482  $sSmtpPort = $this->SMTP_PORT;
483  }
484  }
485  if ($blIsSmtp = (bool) ($rHandle = @fsockopen($sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30))) {
486  // closing connection ..
487  fclose($rHandle);
488  }
489  }
490 
491  return $blIsSmtp;
492  }
493 
503  public function sendOrderEmailToUser($oOrder, $sSubject = null)
504  {
505  $myConfig = $this->getConfig();
506 
507  // add user defined stuff if there is any
508  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
509 
510  $oShop = $this->_getShop();
511  $this->_setMailParams($oShop);
512 
513  $oUser = $oOrder->getOrderUser();
514  $this->setUser($oUser);
515 
516  // create messages
517  $oSmarty = $this->_getSmarty();
518  $this->setViewData("order", $oOrder);
519 
520  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
521  $this->setViewData("blShowReviewLink", true);
522  }
523 
524  // Process view data array through oxOutput processor
525  $this->_processViewArray();
526 
527  $this->setBody($oSmarty->fetch($this->_sOrderUserTemplate));
528  $this->setAltBody($oSmarty->fetch($this->_sOrderUserPlainTemplate));
529 
530  // #586A
531  if ($sSubject === null) {
532  if ($oSmarty->template_exists($this->_sOrderUserSubjectTemplate)) {
533  $sSubject = $oSmarty->fetch($this->_sOrderUserSubjectTemplate);
534  } else {
535  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
536  }
537  }
538 
539  $this->setSubject($sSubject);
540 
541  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
542 
543  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
544  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
545 
546  $blSuccess = $this->send();
547 
548  return $blSuccess;
549  }
550 
560  public function sendOrderEmailToOwner($oOrder, $sSubject = null)
561  {
562  $myConfig = $this->getConfig();
563 
564  $oShop = $this->_getShop();
565 
566  // cleanup
567  $this->_clearMailer();
568 
569  // add user defined stuff if there is any
570  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
571 
572  $oUser = $oOrder->getOrderUser();
573  $this->setUser($oUser);
574 
575  // send confirmation to shop owner
576  // send not pretending from order user, as different email domain rise spam filters
577  $this->setFrom($oShop->oxshops__oxowneremail->value);
578 
579  $oLang = oxRegistry::getLang();
580  $iOrderLang = $oLang->getObjectTplLanguage();
581 
582  // if running shop language is different from admin lang. set in config
583  // we have to load shop in config language
584  if ($oShop->getLanguage() != $iOrderLang) {
585  $oShop = $this->_getShop($iOrderLang);
586  }
587 
588  $this->setSmtp($oShop);
589 
590  // create messages
591  $oSmarty = $this->_getSmarty();
592  $this->setViewData("order", $oOrder);
593 
594  // Process view data array through oxoutput processor
595  $this->_processViewArray();
596 
597  $this->setBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerTemplate, false)));
598  $this->setAltBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerPlainTemplate, false)));
599 
600  //Sets subject to email
601  // #586A
602  if ($sSubject === null) {
603  if ($oSmarty->template_exists($this->_sOrderOwnerSubjectTemplate)) {
604  $sSubject = $oSmarty->fetch($this->_sOrderOwnerSubjectTemplate);
605  } else {
606  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
607  }
608  }
609 
610  $this->setSubject($sSubject);
611  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oLang->translateString("order"));
612 
613  if ($oUser->oxuser__oxusername->value != "admin") {
614  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
615  $this->setReplyTo($oUser->oxuser__oxusername->value, $sFullName);
616  }
617 
618  $blSuccess = $this->send();
619 
620  // add user history
621  $oRemark = oxNew("oxremark");
622  $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
623  $oRemark->oxremark__oxparentid = new oxField($oUser->getId(), oxField::T_RAW);
624  $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
625  $oRemark->save();
626 
627 
628  if ($myConfig->getConfigParam('iDebug') == 6) {
629  oxRegistry::getUtils()->showMessageAndExit("");
630  }
631 
632  return $blSuccess;
633  }
634 
644  public function sendRegisterConfirmEmail($oUser, $sSubject = null)
645  {
646  // setting content ident
647 
648  $this->setViewData("contentident", "oxregisteraltemail");
649  $this->setViewData("contentplainident", "oxregisterplainaltemail");
650 
651  // sending email
652  return $this->sendRegisterEmail($oUser, $sSubject);
653  }
654 
664  public function sendRegisterEmail($oUser, $sSubject = null)
665  {
666  // add user defined stuff if there is any
667  $oUser = $this->_addUserRegisterEmail($oUser);
668 
669  // shop info
670  $oShop = $this->_getShop();
671 
672  //set mail params (from, fromName, smtp )
673  $this->_setMailParams($oShop);
674 
675  // create messages
676  $oSmarty = $this->_getSmarty();
677  $this->setUser($oUser);
678 
679  // Process view data array through oxOutput processor
680  $this->_processViewArray();
681 
682  $this->setBody($oSmarty->fetch($this->_sRegisterTemplate));
683  $this->setAltBody($oSmarty->fetch($this->_sRegisterTemplatePlain));
684 
685  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue());
686 
687  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
688 
689  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
690  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
691 
692  return $this->send();
693  }
694 
704  public function sendForgotPwdEmail($sEmailAddress, $sSubject = null)
705  {
706  $myConfig = $this->getConfig();
707  $oDb = oxDb::getDb();
708 
709  // shop info
710  $oShop = $this->_getShop();
711 
712  // add user defined stuff if there is any
713  $oShop = $this->_addForgotPwdEmail($oShop);
714 
715  //set mail params (from, fromName, smtp)
716  $this->_setMailParams($oShop);
717 
718  // user
719  $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = " . $oDb->quote($sEmailAddress) . " and oxuser.oxpassword != ''";
720  $sOrder = "";
721  if ($myConfig->getConfigParam('blMallUsers')) {
722  $sOrder = "order by oxshopid = '" . $oShop->getId() . "' desc";
723  } else {
724  $sWhere .= " and oxshopid = '" . $oShop->getId() . "'";
725  }
726 
727  $sSelect = "select oxid from oxuser where $sWhere $sOrder";
728  if (($sOxId = $oDb->getOne($sSelect))) {
729 
730  $oUser = oxNew('oxuser');
731  if ($oUser->load($sOxId)) {
732  // create messages
733  $oSmarty = $this->_getSmarty();
734  $this->setUser($oUser);
735 
736  // Process view data array through oxoutput processor
737  $this->_processViewArray();
738 
739  $this->setBody($oSmarty->fetch($this->_sForgotPwdTemplate));
740 
741  $this->setAltBody($oSmarty->fetch($this->_sForgotPwdTemplatePlain));
742 
743  //sets subject of email
744  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue());
745 
746  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
747 
748  $this->setRecipient($sEmailAddress, $sFullName);
749  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
750 
751  if (!$this->send()) {
752  return -1; // failed to send
753  }
754 
755  return true; // success
756  }
757  }
758 
759  return false; // user with this email not found
760  }
761 
772  public function sendContactMail($sEmailAddress = null, $sSubject = null, $sMessage = null)
773  {
774 
775  // shop info
776  $oShop = $this->_getShop();
777 
778  //set mail params (from, fromName, smtp)
779  $this->_setMailParams($oShop);
780 
781  $this->setBody($sMessage);
782  $this->setSubject($sSubject);
783 
784  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
785  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
786  $this->setReplyTo($sEmailAddress, "");
787 
788  return $this->send();
789  }
790 
800  public function sendNewsletterDbOptInMail($oUser, $sSubject = null)
801  {
802  $oLang = oxRegistry::getLang();
803 
804  // add user defined stuff if there is any
805  $oUser = $this->_addNewsletterDbOptInMail($oUser);
806 
807  // shop info
808  $oShop = $this->_getShop();
809 
810  //set mail params (from, fromName, smtp)
811  $this->_setMailParams($oShop);
812 
813  // create messages
814  $oSmarty = $this->_getSmarty();
815  $sConfirmCode = md5($oUser->oxuser__oxusername->value . $oUser->oxuser__oxpasssalt->value);
816  $this->setViewData("subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value, $sConfirmCode));
817  $this->setUser($oUser);
818 
819  // Process view data array through oxOutput processor
820  $this->_processViewArray();
821 
822  $this->setBody($oSmarty->fetch($this->_sNewsletterOptInTemplate));
823  $this->setAltBody($oSmarty->fetch($this->_sNewsletterOptInTemplatePlain));
824  $this->setSubject(($sSubject !== null) ? $sSubject : oxRegistry::getLang()->translateString("NEWSLETTER") . " " . $oShop->oxshops__oxname->getRawValue());
825 
826  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
827 
828  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
829  $this->setFrom($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
830  $this->setReplyTo($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
831 
832  return $this->send();
833  }
834 
843  protected function _getNewsSubsLink($sId, $sConfirmCode = null)
844  {
845  $myConfig = $this->getConfig();
846  $iActShopLang = $myConfig->getActiveShop()->getLanguage();
847 
848  $sUrl = $myConfig->getShopHomeURL() . 'cl=newsletter&amp;fnc=addme&amp;uid=' . $sId;
849  $sUrl .= '&amp;lang=' . $iActShopLang;
850  $sUrl .= ($sConfirmCode) ? '&amp;confirm=' . $sConfirmCode : "";
851 
852  return $sUrl;
853  }
854 
865  public function sendNewsletterMail($oNewsLetter, $oUser, $sSubject = null)
866  {
867  // shop info
868  $oShop = $this->_getShop();
869 
870  //set mail params (from, fromName, smtp)
871  $this->_setMailParams($oShop);
872 
873  $sBody = $oNewsLetter->getHtmlText();
874 
875  if (!empty($sBody)) {
876  $this->setBody($sBody);
877  $this->setAltBody($oNewsLetter->getPlainText());
878  } else {
879  $this->isHtml(false);
880  $this->setBody($oNewsLetter->getPlainText());
881  }
882 
883  $this->setSubject(($sSubject !== null) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue());
884 
885  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
886  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
887  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
888 
889  return $this->send();
890  }
891 
892 
902  public function sendSuggestMail($oParams, $oProduct)
903  {
904  $myConfig = $this->getConfig();
905 
906  //sets language of shop
907  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
908 
909  // shop info
910  $oShop = $this->_getShop($iCurrLang);
911 
912  //sets language to article
913  if ($oProduct->getLanguage() != $iCurrLang) {
914  $oProduct->setLanguage($iCurrLang);
915  $oProduct->load($oProduct->getId());
916  }
917 
918  // mailer stuff
919  // send not pretending from suggesting user, as different email domain rise spam filters
920  $this->setFrom($oShop->oxshops__oxinfoemail->value);
921  $this->setSMTP();
922 
923  // create messages
924  $oSmarty = $this->_getSmarty();
925  $this->setViewData("product", $oProduct);
926  $this->setUser($oParams);
927 
928  $sArticleUrl = $oProduct->getLink();
929 
930  //setting recommended user id
931  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
932  $sArticleUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sArticleUrl);
933  $sArticleUrl .= "su=" . $oActiveUser->getId();
934  }
935 
936  $this->setViewData("sArticleUrl", $sArticleUrl);
937 
938  // Process view data array through oxOutput processor
939  $this->_processViewArray();
940 
941  $this->setBody($oSmarty->fetch($this->_sSuggestTemplate));
942  $this->setAltBody($oSmarty->fetch($this->_sSuggestTemplatePlain));
943  $this->setSubject($oParams->send_subject);
944 
945  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
946  $this->setReplyTo($oParams->send_email, $oParams->send_name);
947 
948  return $this->send();
949  }
950 
959  public function sendInviteMail($oParams)
960  {
961  $myConfig = $this->getConfig();
962 
963  //sets language of shop
964  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
965 
966  // shop info
967  $oShop = $this->_getShop($iCurrLang);
968 
969  // mailer stuff
970  $this->setFrom($oParams->send_email, $oParams->send_name);
971  $this->setSMTP();
972 
973  // create messages
974  $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
975  $this->setUser($oParams);
976 
977  $sHomeUrl = $this->getViewConfig()->getHomeLink();
978 
979  //setting recommended user id
980  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
981  $sHomeUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
982  $sHomeUrl .= "su=" . $oActiveUser->getId();
983  }
984 
985  if (is_array($oParams->rec_email) && count($oParams->rec_email) > 0) {
986  foreach ($oParams->rec_email as $sEmail) {
987  if (!empty($sEmail)) {
988  $sRegisterUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
989  //setting recipient user email
990  $sRegisterUrl .= "re=" . md5($sEmail);
991  $this->setViewData("sHomeUrl", $sRegisterUrl);
992 
993  // Process view data array through oxoutput processor
994  $this->_processViewArray();
995 
996  $this->setBody($oSmarty->fetch($this->_sInviteTemplate));
997 
998  $this->setAltBody($oSmarty->fetch($this->_sInviteTemplatePlain));
999  $this->setSubject($oParams->send_subject);
1000 
1001  $this->setRecipient($sEmail);
1002  $this->setReplyTo($oParams->send_email, $oParams->send_name);
1003  $this->send();
1004  $this->clearAllRecipients();
1005  }
1006  }
1007 
1008  return true;
1009  }
1010 
1011  return false;
1012  }
1013 
1023  public function sendSendedNowMail($oOrder, $sSubject = null)
1024  {
1025  $myConfig = $this->getConfig();
1026 
1027  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1028 
1029  // shop info
1030  $oShop = $this->_getShop($iOrderLang);
1031 
1032  //set mail params (from, fromName, smtp)
1033  $this->_setMailParams($oShop);
1034 
1035  //create messages
1036  $oLang = oxRegistry::getLang();
1037  $oSmarty = $this->_getSmarty();
1038  $this->setViewData("order", $oOrder);
1039  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1040 
1041  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
1042  $this->setViewData("blShowReviewLink", true);
1043  $oUser = oxNew('oxuser');
1044  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1045  }
1046 
1047  // Process view data array through oxoutput processor
1048  $this->_processViewArray();
1049 
1050  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1051  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1052  //V send email in order language
1053  $iOldTplLang = $oLang->getTplLanguage();
1054  $iOldBaseLang = $oLang->getTplLanguage();
1055  $oLang->setTplLanguage($iOrderLang);
1056  $oLang->setBaseLanguage($iOrderLang);
1057 
1058  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1059  // force non admin to get correct paths (tpl, img)
1060  $myConfig->setAdminMode(false);
1061  $this->setBody($oSmarty->fetch($this->_sSenedNowTemplate));
1062  $this->setAltBody($oSmarty->fetch($this->_sSenedNowTemplatePlain));
1063  $myConfig->setAdminMode(true);
1064  $oLang->setTplLanguage($iOldTplLang);
1065  $oLang->setBaseLanguage($iOldBaseLang);
1066  // set it back
1067  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1068 
1069  //Sets subject to email
1070  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue());
1071 
1072  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1073 
1074  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1075  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1076 
1077  return $this->send();
1078  }
1079 
1089  public function sendDownloadLinksMail($oOrder, $sSubject = null)
1090  {
1091  $myConfig = $this->getConfig();
1092 
1093  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1094 
1095  // shop info
1096  $oShop = $this->_getShop($iOrderLang);
1097 
1098  //set mail params (from, fromName, smtp)
1099  $this->_setMailParams($oShop);
1100 
1101  //create messages
1102  $oLang = oxRegistry::getLang();
1103  $oSmarty = $this->_getSmarty();
1104  $this->setViewData("order", $oOrder);
1105  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1106 
1107  $oUser = oxNew('oxuser');
1108  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1109 
1110  // Process view data array through oxoutput processor
1111  $this->_processViewArray();
1112 
1113  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1114  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1115  //V send email in order language
1116  $iOldTplLang = $oLang->getTplLanguage();
1117  $iOldBaseLang = $oLang->getTplLanguage();
1118  $oLang->setTplLanguage($iOrderLang);
1119  $oLang->setBaseLanguage($iOrderLang);
1120 
1121  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1122  // force non admin to get correct paths (tpl, img)
1123  $myConfig->setAdminMode(false);
1124  $this->setBody($oSmarty->fetch($this->_sSendDownloadsTemplate));
1125  $this->setAltBody($oSmarty->fetch($this->_sSendDownloadsTemplatePlain));
1126  $myConfig->setAdminMode(true);
1127  $oLang->setTplLanguage($iOldTplLang);
1128  $oLang->setBaseLanguage($iOldBaseLang);
1129  // set it back
1130  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1131 
1132  //Sets subject to email
1133  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString("DOWNLOAD_LINKS", null, false));
1134 
1135  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1136 
1137  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1138  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1139 
1140  return $this->send();
1141  }
1142 
1157  public function sendBackupMail($aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError)
1158  {
1159  // shop info
1160  $oShop = $this->_getShop();
1161 
1162  //set mail params (from, fromName, smtp)
1163  $this->_setMailParams($oShop);
1164 
1165  $this->setBody($sMessage);
1166  $this->setSubject($sSubject);
1167 
1168  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
1169  $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
1170 
1171  $this->setFrom($sEmailAddress, "");
1172  $this->setReplyTo($sEmailAddress, "");
1173 
1174  //attaching files
1175  $blAttashSucc = true;
1176  $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
1177  foreach ($aAttFiles as $iNum => $sAttFile) {
1178  $sFullPath = $sAttPath . $sAttFile;
1179  if (@is_readable($sFullPath) && @is_file($sFullPath)) {
1180  $blAttashSucc = $this->addAttachment($sFullPath, $sAttFile);
1181  } else {
1182  $blAttashSucc = false;
1183  $aError[] = array(5, $sAttFile); //"Error: backup file $sAttFile not found";
1184  }
1185  }
1186 
1187  if (!$blAttashSucc) {
1188  $aError[] = array(4, ""); //"Error: backup files was not sent to email ...";
1189  $this->clearAttachments();
1190 
1191  return false;
1192  }
1193 
1194  $aStatus[] = 3; //"Mailing backup files ...";
1195  $blSend = $this->send();
1196  $this->clearAttachments();
1197 
1198  return $blSend;
1199  }
1200 
1211  public function sendEmail($sTo, $sSubject, $sBody)
1212  {
1213  //set mail params (from, fromName, smtp)
1214  $this->_setMailParams();
1215 
1216  if (is_array($sTo)) {
1217  foreach ($sTo as $sAddress) {
1218  $this->setRecipient($sAddress, "");
1219  $this->setReplyTo($sAddress, "");
1220  }
1221  } else {
1222  $this->setRecipient($sTo, "");
1223  $this->setReplyTo($sTo, "");
1224  }
1225 
1226  //may be changed later
1227  $this->isHtml(false);
1228 
1229  $this->setSubject($sSubject);
1230  $this->setBody($sBody);
1231 
1232  return $this->send();
1233  }
1234 
1243  public function sendStockReminder($aBasketContents, $sSubject = null)
1244  {
1245  $blSend = false;
1246 
1247  $oArticleList = oxNew("oxarticlelist");
1248  $oArticleList->loadStockRemindProducts($aBasketContents);
1249 
1250  // nothing to remind?
1251  if ($oArticleList->count()) {
1252  $oShop = $this->_getShop();
1253 
1254  //set mail params (from, fromName, smtp... )
1255  $this->_setMailParams($oShop);
1256  $oLang = oxRegistry::getLang();
1257 
1258  $oSmarty = $this->_getSmarty();
1259  $this->setViewData("articles", $oArticleList);
1260 
1261  // Process view data array through oxOutput processor
1262  $this->_processViewArray();
1263 
1264  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1265  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1266  $this->setBody($oSmarty->fetch($this->getConfig()->getTemplatePath($this->_sReminderMailTemplate, false)));
1267  $this->setAltBody("");
1268  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('STOCK_LOW'));
1269 
1270  $blSend = $this->send();
1271  }
1272 
1273  return $blSend;
1274  }
1275 
1284  public function sendWishlistMail($oParams)
1285  {
1286  $myConfig = $this->getConfig();
1287 
1288  $this->_clearMailer();
1289 
1290  // shop info
1291  $oShop = $this->_getShop();
1292 
1293  // mailer stuff
1294  $this->setFrom($oParams->send_email, $oParams->send_name);
1295  $this->setSMTP();
1296 
1297  // create messages
1298  $oSmarty = $this->_getSmarty();
1299  $this->setUser($oParams);
1300 
1301  // Process view data array through oxoutput processor
1302  $this->_processViewArray();
1303 
1304  $this->setBody($oSmarty->fetch($this->_sWishListTemplate));
1305  $this->setAltBody($oSmarty->fetch($this->_sWishListTemplatePlain));
1306  $this->setSubject($oParams->send_subject);
1307 
1308  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
1309  $this->setReplyTo($oParams->send_email, $oParams->send_name);
1310 
1311  return $this->send();
1312  }
1313 
1324  public function sendPriceAlarmNotification($aParams, $oAlarm, $sSubject = null)
1325  {
1326  $this->_clearMailer();
1327  $oShop = $this->_getShop();
1328 
1329  //set mail params (from, fromName, smtp)
1330  $this->_setMailParams($oShop);
1331 
1332  $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
1333 
1334  $oArticle = oxNew("oxarticle");
1335  //$oArticle->setSkipAbPrice( true );
1336  $oArticle->loadInLang($iAlarmLang, $aParams['aid']);
1337  $oLang = oxRegistry::getLang();
1338 
1339  // create messages
1340  $oSmarty = $this->_getSmarty();
1341  $this->setViewData("product", $oArticle);
1342  $this->setViewData("email", $aParams['email']);
1343  $this->setViewData("bidprice", $oLang->formatCurrency($oAlarm->oxpricealarm__oxprice->value, $oCur));
1344 
1345  // Process view data array through oxOutput processor
1346  $this->_processViewArray();
1347 
1348  $this->setRecipient($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1349  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('PRICE_ALERT_FOR_PRODUCT', $iAlarmLang) . " " . $oArticle->oxarticles__oxtitle->getRawValue());
1350  $this->setBody($oSmarty->fetch($this->_sOwnerPricealarmTemplate));
1351  $this->setFrom($aParams['email'], "");
1352  $this->setReplyTo($aParams['email'], "");
1353 
1354  return $this->send();
1355  }
1356 
1368  public function sendPricealarmToCustomer($sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null)
1369  {
1370  $this->_clearMailer();
1371 
1372  $oShop = $this->_getShop();
1373 
1374  if ($oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
1375  $oShop = oxNew("oxshop");
1376  $oShop->load($oAlarm->oxpricealarm__oxshopid->value);
1377  $this->setShop($oShop);
1378  }
1379 
1380  //set mail params (from, fromName, smtp)
1381  $this->_setMailParams($oShop);
1382 
1383  // create messages
1384  $oSmarty = $this->_getSmarty();
1385 
1386  $this->setViewData("product", $oAlarm->getArticle());
1387  $this->setViewData("oPriceAlarm", $oAlarm);
1388  $this->setViewData("bidprice", $oAlarm->getFProposedPrice());
1389  $this->setViewData("currency", $oAlarm->getPriceAlarmCurrency());
1390 
1391  // Process view data array through oxoutput processor
1392  $this->_processViewArray();
1393 
1394  $this->setRecipient($sRecipient, $sRecipient);
1395  $this->setSubject($oShop->oxshops__oxname->value);
1396 
1397  if ($sBody === null) {
1398  $sBody = $oSmarty->fetch($this->_sPricealamrCustomerTemplate);
1399  }
1400 
1401  $this->setBody($sBody);
1402 
1403  $this->addAddress($sRecipient, $sRecipient);
1404  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1405 
1406  if ($sReturnMailBody) {
1407  return $this->getBody();
1408  } else {
1409  return $this->send();
1410  }
1411  }
1412 
1422  protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
1423  {
1424  $sBody = $this->getBody();
1425  if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
1426 
1427  $oFileUtils = oxRegistry::get("oxUtilsFile");
1428  $blReSetBody = false;
1429 
1430  // preparing imput
1431  $sDynImageDir = $oFileUtils->normalizeDir($sDynImageDir);
1432  $sImageDir = $oFileUtils->normalizeDir($sImageDir);
1433  $sImageDirNoSSL = $oFileUtils->normalizeDir($sImageDirNoSSL);
1434 
1435  if (is_array($matches) && count($matches)) {
1436  $aImageCache = array();
1437  $myUtils = oxRegistry::getUtils();
1438  $myUtilsObject = oxUtilsObject::getInstance();
1439  $oImgGenerator = oxNew("oxDynImgGenerator");
1440 
1441  foreach ($matches as $aImage) {
1442 
1443  $image = $aImage[1];
1444  $sFileName = '';
1445  if (strpos($image, $sDynImageDir) === 0) {
1446  $sFileName = $oFileUtils->normalizeDir($sAbsDynImageDir) . str_replace($sDynImageDir, '', $image);
1447  } elseif (strpos($image, $sImageDir) === 0) {
1448  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDir, '', $image);
1449  } elseif (strpos($image, $sImageDirNoSSL) === 0) {
1450  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDirNoSSL, '', $image);
1451  }
1452 
1453  if ($sFileName && !@is_readable($sFileName)) {
1454  $sFileName = $oImgGenerator->getImagePath($sFileName);
1455  }
1456 
1457  if ($sFileName) {
1458  $sCId = '';
1459  if (isset($aImageCache[$sFileName]) && $aImageCache[$sFileName]) {
1460  $sCId = $aImageCache[$sFileName];
1461  } else {
1462  $sCId = $myUtilsObject->generateUID();
1463  $sMIME = $myUtils->oxMimeContentType($sFileName);
1464  if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
1465  if ($this->addEmbeddedImage($sFileName, $sCId, "image", "base64", $sMIME)) {
1466  $aImageCache[$sFileName] = $sCId;
1467  } else {
1468  $sCId = '';
1469  }
1470  }
1471  }
1472  if ($sCId && $sCId == $aImageCache[$sFileName]) {
1473  if ($sReplTag = str_replace($image, 'cid:' . $sCId, $aImage[0])) {
1474  $sBody = str_replace($aImage[0], $sReplTag, $sBody);
1475  $blReSetBody = true;
1476  }
1477  }
1478  }
1479  }
1480  }
1481 
1482  if ($blReSetBody) {
1483  $this->setBody($sBody);
1484  }
1485  }
1486  }
1487 
1493  public function setSubject($sSubject = null)
1494  {
1495  // A. HTML entities in subjects must be replaced
1496  $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>'), $sSubject);
1497 
1498  $this->set("Subject", $sSubject);
1499  }
1500 
1506  public function getSubject()
1507  {
1508  return $this->Subject;
1509  }
1510 
1518  public function setBody($sBody = null, $blClearSid = true)
1519  {
1520  if ($blClearSid) {
1521  $sBody = $this->_clearSidFromBody($sBody);
1522  }
1523 
1524  $this->set("Body", $sBody);
1525  }
1526 
1532  public function getBody()
1533  {
1534  return $this->Body;
1535  }
1536 
1544  public function setAltBody($sAltBody = null, $blClearSid = true)
1545  {
1546  if ($blClearSid) {
1547  $sAltBody = $this->_clearSidFromBody($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 
1572  public function setRecipient($sAddress = null, $sName = null)
1573  {
1574  try {
1575  if ($this->getConfig()->isUtf() && function_exists('idn_to_ascii') ) {
1576  $sAddress = idn_to_ascii($sAddress);
1577  }
1578 
1579  parent::AddAddress($sAddress, $sName);
1580 
1581  // copying values as original class does not allow to access recipients array
1582  $this->_aRecipients[] = array($sAddress, $sName);
1583  } catch (Exception $oEx) {
1584  }
1585  }
1586 
1594  public function getRecipient()
1595  {
1596  return $this->_aRecipients;
1597  }
1598 
1602  public function clearAllRecipients()
1603  {
1604  $this->_aRecipients = array();
1606  }
1607 
1617  public function setReplyTo($sEmail = null, $sName = null)
1618  {
1619  if (!oxRegistry::getUtils()->isValidEmail($sEmail)) {
1620  $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
1621  }
1622 
1623  $this->_aReplies[] = array($sEmail, $sName);
1624 
1625  try {
1626  parent::addReplyTo($sEmail, $sName);
1627  } catch (Exception $oEx) {
1628  }
1629  }
1630 
1636  public function getReplyTo()
1637  {
1638  return $this->_aReplies;
1639  }
1640 
1644  public function clearReplyTos()
1645  {
1646  $this->_aReplies = array();
1648  }
1649 
1655  public function setFrom($address, $name = null, $auto = true)
1656  {
1657  $address = substr($address, 0, 150);
1658  $name = substr($name, 0, 150);
1659 
1660  $success = false;
1661  try {
1662  $success = parent::setFrom($address, $name, $auto);
1663  } catch (Exception $exception) {
1664  }
1665 
1666  return $success;
1667  }
1668 
1674  public function getFrom()
1675  {
1676  return $this->From;
1677  }
1678 
1684  public function getFromName()
1685  {
1686  return $this->FromName;
1687  }
1688 
1695  public function setCharSet($sCharSet = null)
1696  {
1697  if ($sCharSet) {
1698  $this->_sCharSet = $sCharSet;
1699  } else {
1700  $this->_sCharSet = oxRegistry::getLang()->translateString("charset");
1701  }
1702  $this->set("CharSet", $this->_sCharSet);
1703  }
1704 
1710  public function setMailer($sMailer = null)
1711  {
1712  $this->set("Mailer", $sMailer);
1713  }
1714 
1720  public function getMailer()
1721  {
1722  return $this->Mailer;
1723  }
1724 
1730  public function setHost($sHost = null)
1731  {
1732  $this->set("Host", $sHost);
1733  }
1734 
1740  public function getErrorInfo()
1741  {
1742  return $this->ErrorInfo;
1743  }
1744 
1751  public function setMailWordWrap($iWordWrap = null)
1752  {
1753  $this->set("WordWrap", $iWordWrap);
1754  }
1755 
1761  public function setUseInlineImages($blUseImages = null)
1762  {
1763  $this->_blInlineImgEmail = $blUseImages;
1764  }
1765 
1769  public function addAttachment(
1770  $path,
1771  $name = '',
1772  $encoding = 'base64',
1773  $type = 'application/octet-stream',
1774  $disposition = 'attachment'
1775  ) {
1776  $this->_aAttachments[] = array($path, $name, $encoding, $type, $disposition);
1777  $result = false;
1778 
1779  try {
1780  $result = parent::addAttachment($path, $name, $encoding, $type, $disposition);
1781  } catch (Exception $exception) {
1782  }
1783 
1784  return $result;
1785  }
1786 
1790  public function addEmbeddedImage(
1791  $path,
1792  $cid,
1793  $name = '',
1794  $encoding = 'base64',
1795  $type = 'application/octet-stream',
1796  $disposition = 'inline'
1797  ) {
1798  $this->_aAttachments[] = array(
1799  $path,
1800  basename($path),
1801  $name,
1802  $encoding,
1803  $type,
1804  false,
1805  $disposition,
1806  $cid
1807  );
1808 
1809  return parent::addEmbeddedImage($path, $cid, $name, $encoding, $type, $disposition);
1810  }
1811 
1817  public function getAttachments()
1818  {
1819  return $this->_aAttachments;
1820  }
1821 
1827  public function clearAttachments()
1828  {
1829  $this->_aAttachments = array();
1830 
1831  return parent::clearAttachments();
1832  }
1833 
1843  public function headerLine($sName, $sValue)
1844  {
1845  if (stripos($sName, 'X-') !== false) {
1846  return;
1847  }
1848 
1849  return parent::headerLine($sName, $sValue);
1850  }
1851 
1857  protected function _getUseInlineImages()
1858  {
1859  return $this->_blInlineImgEmail;
1860  }
1861 
1867  protected function _sendMailErrorMsg()
1868  {
1869  // build addresses
1870  $aRecipients = $this->getRecipient();
1871 
1872  $sOwnerMessage = "Error sending eMail(" . $this->getSubject() . ") to: \n\n";
1873 
1874  foreach ($aRecipients as $aEMail) {
1875  $sOwnerMessage .= $aEMail[0];
1876  $sOwnerMessage .= (!empty($aEMail[1])) ? ' (' . $aEMail[1] . ')' : '';
1877  $sOwnerMessage .= " \n ";
1878  }
1879  $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
1880 
1881  // shop info
1882  $oShop = $this->_getShop();
1883 
1884  $blRet = @mail($oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
1885 
1886  return $blRet;
1887  }
1888 
1898  protected function _addUserInfoOrderEMail($oOrder)
1899  {
1900  return $oOrder;
1901  }
1902 
1912  protected function _addUserRegisterEmail($oUser)
1913  {
1914  return $oUser;
1915  }
1916 
1926  protected function _addForgotPwdEmail($oShop)
1927  {
1928  return $oShop;
1929  }
1930 
1940  protected function _addNewsletterDbOptInMail($oUser)
1941  {
1942  return $oUser;
1943  }
1944 
1948  protected function _clearMailer()
1949  {
1950  $this->clearAllRecipients();
1951  $this->clearReplyTos();
1952  $this->clearAttachments();
1953 
1954  //workaround for phpmailer as it doesn't cleanup as it should
1955  $this->error_count = 0;
1956  $this->ErrorInfo = '';
1957  }
1958 
1964  protected function _setMailParams($oShop = null)
1965  {
1966  $this->_clearMailer();
1967 
1968  if (!$oShop) {
1969  $oShop = $this->_getShop();
1970  }
1971 
1972  $this->setFrom($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1973  $this->setSmtp($oShop);
1974  }
1975 
1985  protected function _getShop($iLangId = null, $iShopId = null)
1986  {
1987  if ($iLangId === null && $iShopId === null) {
1988  if (isset($this->_oShop)) {
1989  return $this->_oShop;
1990  } else {
1991  return $this->_oShop = $this->getConfig()->getActiveShop();
1992  }
1993  }
1994 
1995  $myConfig = $this->getConfig();
1996 
1997  $oShop = oxNew('oxShop');
1998  if ($iShopId !== null) {
1999  $oShop->setShopId($iShopId);
2000  }
2001  if ($iLangId !== null) {
2002  $oShop->setLanguage($iLangId);
2003  }
2004  $oShop->load($myConfig->getShopId());
2005 
2006  return $oShop;
2007  }
2008 
2015  protected function _setSmtpAuthInfo($sUserName = null, $sUserPassword = null)
2016  {
2017  $this->set("SMTPAuth", true);
2018  $this->set("Username", $sUserName);
2019  $this->set("Password", $sUserPassword);
2020  }
2021 
2027  protected function _setSmtpDebug($blDebug = null)
2028  {
2029  $this->set("SMTPDebug", $blDebug);
2030  }
2031 
2035  protected function _setMailerPluginDir()
2036  {
2037  $this->set("PluginDir", getShopBasePath() . "core/phpmailer/");
2038  }
2039 
2044  protected function _makeOutputProcessing()
2045  {
2046  $oOutput = oxNew("oxOutput");
2047  $this->setBody($oOutput->process($this->getBody(), "oxemail"));
2048  $this->setAltBody($oOutput->process($this->getAltBody(), "oxemail"));
2049  $oOutput->processEmail($this);
2050  }
2051 
2057  protected function _sendMail()
2058  {
2059  $blResult = false;
2060  try {
2061  $blResult = parent::send();
2062  } catch (Exception $oException) {
2063  $oEx = oxNew("oxException");
2064  $oEx->setMessage($oException->getMessage());
2065  $oEx->debugOut();
2066  if ($this->getConfig()->getConfigParam('iDebug') != 0) {
2067  throw $oEx;
2068  }
2069  }
2070 
2071  return $blResult;
2072  }
2073 
2074 
2078  protected function _processViewArray()
2079  {
2080  $oSmarty = $this->_getSmarty();
2081  $oOutputProcessor = oxNew("oxOutput");
2082 
2083  // processing all view data
2084  foreach ($this->_aViewData as $sKey => $sValue) {
2085  $oSmarty->assign($sKey, $sValue);
2086  }
2087 
2088  // processing assigned smarty variables
2089  $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
2090 
2091  foreach ($aNewSmartyArray as $key => $val) {
2092  $oSmarty->assign($key, $val);
2093  }
2094  }
2095 
2101  public function getCharset()
2102  {
2103  if (!$this->_sCharSet) {
2104  return oxRegistry::getLang()->translateString("charset");
2105  } else {
2106  return $this->CharSet;
2107  }
2108  }
2109 
2115  public function getShop()
2116  {
2117  return $this->_getShop();
2118  }
2119 
2125  public function setShop($oShop)
2126  {
2127  $this->_oShop = $oShop;
2128  }
2129 
2135  public function getViewConfig()
2136  {
2137  return $this->getConfig()->getActiveView()->getViewConfig();
2138  }
2139 
2145  public function getView()
2146  {
2147  return $this->getConfig()->getActiveView();
2148  }
2149 
2155  public function getCurrency()
2156  {
2157  $oConfig = oxRegistry::getConfig();
2158 
2159  return $oConfig->getActShopCurrencyObject();
2160  }
2161 
2168  public function setViewData($sKey, $sValue)
2169  {
2170  $this->_aViewData[$sKey] = $sValue;
2171  }
2172 
2178  public function getViewData()
2179  {
2180  return $this->_aViewData;
2181  }
2182 
2190  public function getViewDataItem($sKey)
2191  {
2192  if (isset($this->_aViewData[$sKey])) {
2193  return $this->_aViewData;
2194  }
2195  }
2196 
2202  public function setUser($oUser)
2203  {
2204  $this->_aViewData["oUser"] = $oUser;
2205  }
2206 
2212  public function getUser()
2213  {
2214  return $this->_aViewData["oUser"];
2215  }
2216 
2224  public function getOrderFileList($sOrderId)
2225  {
2226  $oOrderList = oxNew('oxOrderFileList');
2227  $oOrderList->loadOrderFiles($sOrderId);
2228 
2229  if (count($oOrderList) > 0) {
2230  return $oOrderList;
2231  }
2232 
2233  return false;
2234  }
2235 
2243  private function _clearSidFromBody($sAltBody)
2244  {
2245  return oxStr::getStr()->preg_replace('/(\?|&(amp;)?)(force_)?(admin_)?sid=[A-Z0-9\.]+/i', '\1shp=' . $this->getConfig()->getShopId(), $sAltBody);
2246  }
2247 }