OXID eShop CE  4.9.7
 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 {
15 
21  public $SMTP_PORT = 25;
22 
28  protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
29 
35  protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
36 
42  protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
43 
49  protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
50 
56  protected $_sSuggestTemplate = "email/html/suggest.tpl";
57 
63  protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
64 
70  protected $_sInviteTemplate = "email/html/invite.tpl";
71 
77  protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
78 
84  protected $_sSenedNowTemplate = "email/html/ordershipped.tpl";
85 
91  protected $_sSenedNowTemplatePlain = "email/plain/ordershipped.tpl";
92 
98  protected $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
99 
105  protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
106 
112  protected $_sWishListTemplate = "email/html/wishlist.tpl";
113 
119  protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
120 
126  protected $_sRegisterTemplate = "email/html/register.tpl";
127 
133  protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
134 
140  protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
141 
147  protected $_sOrderUserTemplate = "email/html/order_cust.tpl";
148 
154  protected $_sOrderUserPlainTemplate = "email/plain/order_cust.tpl";
155 
161  protected $_sOrderOwnerTemplate = "email/html/order_owner.tpl";
162 
168  protected $_sOrderOwnerPlainTemplate = "email/plain/order_owner.tpl";
169 
170  // #586A - additional templates for more customizable subjects
171 
177  protected $_sOrderUserSubjectTemplate = "email/html/order_cust_subj.tpl";
178 
184  protected $_sOrderOwnerSubjectTemplate = "email/html/order_owner_subj.tpl";
185 
191  protected $_sOwnerPricealarmTemplate = "email/html/pricealarm_owner.tpl";
192 
198  protected $_sPricealamrCustomerTemplate = "email_pricealarm_customer.tpl";
199 
205  protected $_aShops = array();
206 
212  protected $_blInlineImgEmail = null;
213 
219  protected $_aRecipients = array();
220 
226  protected $_aReplies = array();
227 
233  protected $_aAttachments = array();
234 
240  protected $_oSmarty = null;
241 
247  protected $_aViewData = array();
248 
254  protected $_oShop = null;
255 
261  protected $_sCharSet = null;
262 
266  public function __construct()
267  {
268  //enabling exception handling in phpmailer class
269  parent::__construct(true);
270 
271  $myConfig = $this->getConfig();
272 
273  $this->_setMailerPluginDir();
274  $this->setSmtp();
275 
276  $this->setUseInlineImages($myConfig->getConfigParam('blInlineImgEmail'));
277  $this->setMailWordWrap(100);
278 
279  $this->isHtml(true);
280  $this->setLanguage("en", $myConfig->getConfigParam('sShopDir') . "/core/phpmailer/language/");
281 
282  $this->_getSmarty();
283  }
284 
296  public function __call($sMethod, $aArgs)
297  {
298  if (defined('OXID_PHP_UNIT')) {
299  if (substr($sMethod, 0, 4) == "UNIT") {
300  $sMethod = str_replace("UNIT", "_", $sMethod);
301  }
302  if (method_exists($this, $sMethod)) {
303  return call_user_func_array(array(& $this, $sMethod), $aArgs);
304  }
305  }
306 
307  throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")" . PHP_EOL);
308  }
309 
315  public function getConfig()
316  {
317  if ($this->_oConfig == null) {
318  $this->_oConfig = oxRegistry::getConfig();
319  }
320 
321  return $this->_oConfig;
322  }
323 
329  public function setConfig($oConfig)
330  {
331  $this->_oConfig = $oConfig;
332  }
333 
334 
340  protected function _getSmarty()
341  {
342  if ($this->_oSmarty === null) {
343  $this->_oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
344  }
345 
346  //setting default view
347  $this->_oSmarty->assign("oEmailView", $this);
348 
349  return $this->_oSmarty;
350  }
351 
359  public function send()
360  {
361  // if no recipients found, skipping sending
362  if (count($this->getRecipient()) < 1) {
363  return false;
364  }
365 
366  $myConfig = $this->getConfig();
367  $this->setCharSet();
368 
369  if ($this->_getUseInlineImages()) {
370  $this->_includeImages(
371  $myConfig->getImageDir(), $myConfig->getImageUrl(false, false), $myConfig->getPictureUrl(null, false),
372  $myConfig->getImageDir(), $myConfig->getPictureDir(false)
373  );
374  }
375 
376  $this->_makeOutputProcessing();
377 
378  // try to send mail via SMTP
379  if ($this->getMailer() == 'smtp') {
380  $blRet = $this->_sendMail();
381 
382  // if sending failed, try to send via mail()
383  if (!$blRet) {
384  // failed sending via SMTP, sending notification to shop owner
385  $this->_sendMailErrorMsg();
386 
387  // trying to send using standard mailer
388  $this->setMailer('mail');
389  $blRet = $this->_sendMail();
390  }
391  } else {
392  // sending mail via mail()
393  $this->setMailer('mail');
394  $blRet = $this->_sendMail();
395  }
396 
397  if (!$blRet) {
398  // failed sending, giving up, trying to send notification to shop owner
399  $this->_sendMailErrorMsg();
400  }
401 
402  return $blRet;
403  }
404 
413  protected function _setSmtpProtocol($sUrl)
414  {
415  $sProtocol = '';
416  $sSmtpHost = $sUrl;
417  $aMatch = array();
418  if (getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch)) {
419  if ($aMatch[1]) {
420  if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
421  $this->set("SMTPSecure", substr($aMatch[1], 0, 3));
422  } else {
423  $sProtocol = $aMatch[1];
424  }
425  }
426  $sSmtpHost = $aMatch[2];
427  }
428 
429  return $sProtocol . $sSmtpHost;
430  }
431 
439  public function setSmtp($oShop = null)
440  {
441  $myConfig = $this->getConfig();
442  $oShop = ($oShop) ? $oShop : $this->_getShop();
443 
444  $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
445 
446  if (!$this->_isValidSmtpHost($sSmtpUrl)) {
447  $this->setMailer("mail");
448 
449  return;
450  }
451 
452  $this->setHost($sSmtpUrl);
453  $this->setMailer("smtp");
454 
455  if ($oShop->oxshops__oxsmtpuser->value) {
456  $this->_setSmtpAuthInfo($oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value);
457  }
458 
459  if ($myConfig->getConfigParam('iDebug') == 6) {
460  $this->_setSmtpDebug(true);
461  }
462  }
463 
471  protected function _isValidSmtpHost($sSmtpHost)
472  {
473  $blIsSmtp = false;
474  if ($sSmtpHost) {
475  $sSmtpPort = $this->SMTP_PORT;
476  $aMatch = array();
477  if (getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
478  $sSmtpHost = $aMatch[1];
479  $sSmtpPort = (int) $aMatch[3];
480  if (!$sSmtpPort) {
481  $sSmtpPort = $this->SMTP_PORT;
482  }
483  }
484  if ($blIsSmtp = (bool) ($rHandle = @fsockopen($sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30))) {
485  // closing connection ..
486  fclose($rHandle);
487  }
488  }
489 
490  return $blIsSmtp;
491  }
492 
502  public function sendOrderEmailToUser($oOrder, $sSubject = null)
503  {
504  $myConfig = $this->getConfig();
505 
506  // add user defined stuff if there is any
507  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
508 
509  $oShop = $this->_getShop();
510  $this->_setMailParams($oShop);
511 
512  $oUser = $oOrder->getOrderUser();
513  $this->setUser($oUser);
514 
515  // create messages
516  $oSmarty = $this->_getSmarty();
517  $this->setViewData("order", $oOrder);
518 
519  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
520  $this->setViewData("blShowReviewLink", true);
521  }
522 
523  // Process view data array through oxOutput processor
524  $this->_processViewArray();
525 
526  $this->setBody($oSmarty->fetch($this->_sOrderUserTemplate));
527  $this->setAltBody($oSmarty->fetch($this->_sOrderUserPlainTemplate));
528 
529  // #586A
530  if ($sSubject === null) {
531  if ($oSmarty->template_exists($this->_sOrderUserSubjectTemplate)) {
532  $sSubject = $oSmarty->fetch($this->_sOrderUserSubjectTemplate);
533  } else {
534  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
535  }
536  }
537 
538  $this->setSubject($sSubject);
539 
540  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
541 
542  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
543  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
544 
545  $blSuccess = $this->send();
546 
547  return $blSuccess;
548  }
549 
559  public function sendOrderEmailToOwner($oOrder, $sSubject = null)
560  {
561  $myConfig = $this->getConfig();
562 
563  $oShop = $this->_getShop();
564 
565  // cleanup
566  $this->_clearMailer();
567 
568  // add user defined stuff if there is any
569  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
570 
571  $oUser = $oOrder->getOrderUser();
572  $this->setUser($oUser);
573 
574  // send confirmation to shop owner
575  // send not pretending from order user, as different email domain rise spam filters
576  $this->setFrom($oShop->oxshops__oxowneremail->value);
577 
578  $oLang = oxRegistry::getLang();
579  $iOrderLang = $oLang->getObjectTplLanguage();
580 
581  // if running shop language is different from admin lang. set in config
582  // we have to load shop in config language
583  if ($oShop->getLanguage() != $iOrderLang) {
584  $oShop = $this->_getShop($iOrderLang);
585  }
586 
587  $this->setSmtp($oShop);
588 
589  // create messages
590  $oSmarty = $this->_getSmarty();
591  $this->setViewData("order", $oOrder);
592 
593  // Process view data array through oxoutput processor
594  $this->_processViewArray();
595 
596  $this->setBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerTemplate, false)));
597  $this->setAltBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerPlainTemplate, false)));
598 
599  //Sets subject to email
600  // #586A
601  if ($sSubject === null) {
602  if ($oSmarty->template_exists($this->_sOrderOwnerSubjectTemplate)) {
603  $sSubject = $oSmarty->fetch($this->_sOrderOwnerSubjectTemplate);
604  } else {
605  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
606  }
607  }
608 
609  $this->setSubject($sSubject);
610  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oLang->translateString("order"));
611 
612  if ($oUser->oxuser__oxusername->value != "admin") {
613  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
614  $this->setReplyTo($oUser->oxuser__oxusername->value, $sFullName);
615  }
616 
617  $blSuccess = $this->send();
618 
619  // add user history
620  $oRemark = oxNew("oxremark");
621  $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
622  $oRemark->oxremark__oxparentid = new oxField($oUser->getId(), oxField::T_RAW);
623  $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
624  $oRemark->save();
625 
626 
627  if ($myConfig->getConfigParam('iDebug') == 6) {
628  oxRegistry::getUtils()->showMessageAndExit("");
629  }
630 
631  return $blSuccess;
632  }
633 
643  public function sendRegisterConfirmEmail($oUser, $sSubject = null)
644  {
645  // setting content ident
646 
647  $this->setViewData("contentident", "oxregisteraltemail");
648  $this->setViewData("contentplainident", "oxregisterplainaltemail");
649 
650  // sending email
651  return $this->sendRegisterEmail($oUser, $sSubject);
652  }
653 
663  public function sendRegisterEmail($oUser, $sSubject = null)
664  {
665  // add user defined stuff if there is any
666  $oUser = $this->_addUserRegisterEmail($oUser);
667 
668  // shop info
669  $oShop = $this->_getShop();
670 
671  //set mail params (from, fromName, smtp )
672  $this->_setMailParams($oShop);
673 
674  // create messages
675  $oSmarty = $this->_getSmarty();
676  $this->setUser($oUser);
677 
678  // Process view data array through oxOutput processor
679  $this->_processViewArray();
680 
681  $this->setBody($oSmarty->fetch($this->_sRegisterTemplate));
682  $this->setAltBody($oSmarty->fetch($this->_sRegisterTemplatePlain));
683 
684  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue());
685 
686  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
687 
688  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
689  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
690 
691  return $this->send();
692  }
693 
703  public function sendForgotPwdEmail($sEmailAddress, $sSubject = null)
704  {
705  $myConfig = $this->getConfig();
706  $oDb = oxDb::getDb();
707 
708  // shop info
709  $oShop = $this->_getShop();
710 
711  // add user defined stuff if there is any
712  $oShop = $this->_addForgotPwdEmail($oShop);
713 
714  //set mail params (from, fromName, smtp)
715  $this->_setMailParams($oShop);
716 
717  // user
718  $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = " . $oDb->quote($sEmailAddress) . " and oxuser.oxpassword != ''";
719  $sOrder = "";
720  if ($myConfig->getConfigParam('blMallUsers')) {
721  $sOrder = "order by oxshopid = '" . $oShop->getId() . "' desc";
722  } else {
723  $sWhere .= " and oxshopid = '" . $oShop->getId() . "'";
724  }
725 
726  $sSelect = "select oxid from oxuser where $sWhere $sOrder";
727  if (($sOxId = $oDb->getOne($sSelect))) {
728 
729  $oUser = oxNew('oxuser');
730  if ($oUser->load($sOxId)) {
731  // create messages
732  $oSmarty = $this->_getSmarty();
733  $this->setUser($oUser);
734 
735  // Process view data array through oxoutput processor
736  $this->_processViewArray();
737 
738  $this->setBody($oSmarty->fetch($this->_sForgotPwdTemplate));
739 
740  $this->setAltBody($oSmarty->fetch($this->_sForgotPwdTemplatePlain));
741 
742  //sets subject of email
743  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue());
744 
745  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
746 
747  $this->setRecipient($sEmailAddress, $sFullName);
748  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
749 
750  if (!$this->send()) {
751  return -1; // failed to send
752  }
753 
754  return true; // success
755  }
756  }
757 
758  return false; // user with this email not found
759  }
760 
771  public function sendContactMail($sEmailAddress = null, $sSubject = null, $sMessage = null)
772  {
773 
774  // shop info
775  $oShop = $this->_getShop();
776 
777  //set mail params (from, fromName, smtp)
778  $this->_setMailParams($oShop);
779 
780  $this->setBody($sMessage);
781  $this->setSubject($sSubject);
782 
783  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
784  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
785  $this->setReplyTo($sEmailAddress, "");
786 
787  return $this->send();
788  }
789 
799  public function sendNewsletterDbOptInMail($oUser, $sSubject = null)
800  {
801  $oLang = oxRegistry::getLang();
802 
803  // add user defined stuff if there is any
804  $oUser = $this->_addNewsletterDbOptInMail($oUser);
805 
806  // shop info
807  $oShop = $this->_getShop();
808 
809  //set mail params (from, fromName, smtp)
810  $this->_setMailParams($oShop);
811 
812  // create messages
813  $oSmarty = $this->_getSmarty();
814  $sConfirmCode = md5($oUser->oxuser__oxusername->value . $oUser->oxuser__oxpasssalt->value);
815  $this->setViewData("subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value, $sConfirmCode));
816  $this->setUser($oUser);
817 
818  // Process view data array through oxOutput processor
819  $this->_processViewArray();
820 
821  $this->setBody($oSmarty->fetch($this->_sNewsletterOptInTemplate));
822  $this->setAltBody($oSmarty->fetch($this->_sNewsletterOptInTemplatePlain));
823  $this->setSubject(($sSubject !== null) ? $sSubject : oxRegistry::getLang()->translateString("NEWSLETTER") . " " . $oShop->oxshops__oxname->getRawValue());
824 
825  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
826 
827  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
828  $this->setFrom($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
829  $this->setReplyTo($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
830 
831  return $this->send();
832  }
833 
842  protected function _getNewsSubsLink($sId, $sConfirmCode = null)
843  {
844  $myConfig = $this->getConfig();
845  $iActShopLang = $myConfig->getActiveShop()->getLanguage();
846 
847  $sUrl = $myConfig->getShopHomeURL() . 'cl=newsletter&amp;fnc=addme&amp;uid=' . $sId;
848  $sUrl .= '&amp;lang=' . $iActShopLang;
849  $sUrl .= ($sConfirmCode) ? '&amp;confirm=' . $sConfirmCode : "";
850 
851  return $sUrl;
852  }
853 
864  public function sendNewsletterMail($oNewsLetter, $oUser, $sSubject = null)
865  {
866  // shop info
867  $oShop = $this->_getShop();
868 
869  //set mail params (from, fromName, smtp)
870  $this->_setMailParams($oShop);
871 
872  $sBody = $oNewsLetter->getHtmlText();
873 
874  if (!empty($sBody)) {
875  $this->setBody($sBody);
876  $this->setAltBody($oNewsLetter->getPlainText());
877  } else {
878  $this->isHtml(false);
879  $this->setBody($oNewsLetter->getPlainText());
880  }
881 
882  $this->setSubject(($sSubject !== null) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue());
883 
884  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
885  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
886  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
887 
888  return $this->send();
889  }
890 
891 
901  public function sendSuggestMail($oParams, $oProduct)
902  {
903  $myConfig = $this->getConfig();
904 
905  //sets language of shop
906  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
907 
908  // shop info
909  $oShop = $this->_getShop($iCurrLang);
910 
911  //sets language to article
912  if ($oProduct->getLanguage() != $iCurrLang) {
913  $oProduct->setLanguage($iCurrLang);
914  $oProduct->load($oProduct->getId());
915  }
916 
917  // mailer stuff
918  // send not pretending from suggesting user, as different email domain rise spam filters
919  $this->setFrom($oShop->oxshops__oxinfoemail->value);
920  $this->setSMTP();
921 
922  // create messages
923  $oSmarty = $this->_getSmarty();
924  $this->setViewData("product", $oProduct);
925  $this->setUser($oParams);
926 
927  $sArticleUrl = $oProduct->getLink();
928 
929  //setting recommended user id
930  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
931  $sArticleUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sArticleUrl);
932  $sArticleUrl .= "su=" . $oActiveUser->getId();
933  }
934 
935  $this->setViewData("sArticleUrl", $sArticleUrl);
936 
937  // Process view data array through oxOutput processor
938  $this->_processViewArray();
939 
940  $this->setBody($oSmarty->fetch($this->_sSuggestTemplate));
941  $this->setAltBody($oSmarty->fetch($this->_sSuggestTemplatePlain));
942  $this->setSubject($oParams->send_subject);
943 
944  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
945  $this->setReplyTo($oParams->send_email, $oParams->send_name);
946 
947  return $this->send();
948  }
949 
958  public function sendInviteMail($oParams)
959  {
960  $myConfig = $this->getConfig();
961 
962  //sets language of shop
963  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
964 
965  // shop info
966  $oShop = $this->_getShop($iCurrLang);
967 
968  // mailer stuff
969  $this->setFrom($oParams->send_email, $oParams->send_name);
970  $this->setSMTP();
971 
972  // create messages
973  $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
974  $this->setUser($oParams);
975 
976  $sHomeUrl = $this->getViewConfig()->getHomeLink();
977 
978  //setting recommended user id
979  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
980  $sHomeUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
981  $sHomeUrl .= "su=" . $oActiveUser->getId();
982  }
983 
984  if (is_array($oParams->rec_email) && count($oParams->rec_email) > 0) {
985  foreach ($oParams->rec_email as $sEmail) {
986  if (!empty($sEmail)) {
987  $sRegisterUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
988  //setting recipient user email
989  $sRegisterUrl .= "re=" . md5($sEmail);
990  $this->setViewData("sHomeUrl", $sRegisterUrl);
991 
992  // Process view data array through oxoutput processor
993  $this->_processViewArray();
994 
995  $this->setBody($oSmarty->fetch($this->_sInviteTemplate));
996 
997  $this->setAltBody($oSmarty->fetch($this->_sInviteTemplatePlain));
998  $this->setSubject($oParams->send_subject);
999 
1000  $this->setRecipient($sEmail);
1001  $this->setReplyTo($oParams->send_email, $oParams->send_name);
1002  $this->send();
1003  $this->clearAllRecipients();
1004  }
1005  }
1006 
1007  return true;
1008  }
1009 
1010  return false;
1011  }
1012 
1022  public function sendSendedNowMail($oOrder, $sSubject = null)
1023  {
1024  $myConfig = $this->getConfig();
1025 
1026  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1027 
1028  // shop info
1029  $oShop = $this->_getShop($iOrderLang);
1030 
1031  //set mail params (from, fromName, smtp)
1032  $this->_setMailParams($oShop);
1033 
1034  //create messages
1035  $oLang = oxRegistry::getLang();
1036  $oSmarty = $this->_getSmarty();
1037  $this->setViewData("order", $oOrder);
1038  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1039 
1040  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
1041  $this->setViewData("blShowReviewLink", true);
1042  $oUser = oxNew('oxuser');
1043  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1044  }
1045 
1046  // Process view data array through oxoutput processor
1047  $this->_processViewArray();
1048 
1049  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1050  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1051  //V send email in order language
1052  $iOldTplLang = $oLang->getTplLanguage();
1053  $iOldBaseLang = $oLang->getTplLanguage();
1054  $oLang->setTplLanguage($iOrderLang);
1055  $oLang->setBaseLanguage($iOrderLang);
1056 
1057  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1058  // force non admin to get correct paths (tpl, img)
1059  $myConfig->setAdminMode(false);
1060  $this->setBody($oSmarty->fetch($this->_sSenedNowTemplate));
1061  $this->setAltBody($oSmarty->fetch($this->_sSenedNowTemplatePlain));
1062  $myConfig->setAdminMode(true);
1063  $oLang->setTplLanguage($iOldTplLang);
1064  $oLang->setBaseLanguage($iOldBaseLang);
1065  // set it back
1066  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1067 
1068  //Sets subject to email
1069  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue());
1070 
1071  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1072 
1073  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1074  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1075 
1076  return $this->send();
1077  }
1078 
1088  public function sendDownloadLinksMail($oOrder, $sSubject = null)
1089  {
1090  $myConfig = $this->getConfig();
1091 
1092  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1093 
1094  // shop info
1095  $oShop = $this->_getShop($iOrderLang);
1096 
1097  //set mail params (from, fromName, smtp)
1098  $this->_setMailParams($oShop);
1099 
1100  //create messages
1101  $oLang = oxRegistry::getLang();
1102  $oSmarty = $this->_getSmarty();
1103  $this->setViewData("order", $oOrder);
1104  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1105 
1106  $oUser = oxNew('oxuser');
1107  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1108 
1109  // Process view data array through oxoutput processor
1110  $this->_processViewArray();
1111 
1112  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1113  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1114  //V send email in order language
1115  $iOldTplLang = $oLang->getTplLanguage();
1116  $iOldBaseLang = $oLang->getTplLanguage();
1117  $oLang->setTplLanguage($iOrderLang);
1118  $oLang->setBaseLanguage($iOrderLang);
1119 
1120  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1121  // force non admin to get correct paths (tpl, img)
1122  $myConfig->setAdminMode(false);
1123  $this->setBody($oSmarty->fetch($this->_sSendDownloadsTemplate));
1124  $this->setAltBody($oSmarty->fetch($this->_sSendDownloadsTemplatePlain));
1125  $myConfig->setAdminMode(true);
1126  $oLang->setTplLanguage($iOldTplLang);
1127  $oLang->setBaseLanguage($iOldBaseLang);
1128  // set it back
1129  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1130 
1131  //Sets subject to email
1132  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString("DOWNLOAD_LINKS", null, false));
1133 
1134  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1135 
1136  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1137  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1138 
1139  return $this->send();
1140  }
1141 
1156  public function sendBackupMail($aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError)
1157  {
1158  // shop info
1159  $oShop = $this->_getShop();
1160 
1161  //set mail params (from, fromName, smtp)
1162  $this->_setMailParams($oShop);
1163 
1164  $this->setBody($sMessage);
1165  $this->setSubject($sSubject);
1166 
1167  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
1168  $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
1169 
1170  $this->setFrom($sEmailAddress, "");
1171  $this->setReplyTo($sEmailAddress, "");
1172 
1173  //attaching files
1174  $blAttashSucc = true;
1175  $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
1176  foreach ($aAttFiles as $iNum => $sAttFile) {
1177  $sFullPath = $sAttPath . $sAttFile;
1178  if (@is_readable($sFullPath) && @is_file($sFullPath)) {
1179  $blAttashSucc = $this->addAttachment($sFullPath, $sAttFile);
1180  } else {
1181  $blAttashSucc = false;
1182  $aError[] = array(5, $sAttFile); //"Error: backup file $sAttFile not found";
1183  }
1184  }
1185 
1186  if (!$blAttashSucc) {
1187  $aError[] = array(4, ""); //"Error: backup files was not sent to email ...";
1188  $this->clearAttachments();
1189 
1190  return false;
1191  }
1192 
1193  $aStatus[] = 3; //"Mailing backup files ...";
1194  $blSend = $this->send();
1195  $this->clearAttachments();
1196 
1197  return $blSend;
1198  }
1199 
1210  public function sendEmail($sTo, $sSubject, $sBody)
1211  {
1212  //set mail params (from, fromName, smtp)
1213  $this->_setMailParams();
1214 
1215  if (is_array($sTo)) {
1216  foreach ($sTo as $sAddress) {
1217  $this->setRecipient($sAddress, "");
1218  $this->setReplyTo($sAddress, "");
1219  }
1220  } else {
1221  $this->setRecipient($sTo, "");
1222  $this->setReplyTo($sTo, "");
1223  }
1224 
1225  //may be changed later
1226  $this->isHtml(false);
1227 
1228  $this->setSubject($sSubject);
1229  $this->setBody($sBody);
1230 
1231  return $this->send();
1232  }
1233 
1242  public function sendStockReminder($aBasketContents, $sSubject = null)
1243  {
1244  $blSend = false;
1245 
1246  $oArticleList = oxNew("oxarticlelist");
1247  $oArticleList->loadStockRemindProducts($aBasketContents);
1248 
1249  // nothing to remind?
1250  if ($oArticleList->count()) {
1251  $oShop = $this->_getShop();
1252 
1253  //set mail params (from, fromName, smtp... )
1254  $this->_setMailParams($oShop);
1255  $oLang = oxRegistry::getLang();
1256 
1257  $oSmarty = $this->_getSmarty();
1258  $this->setViewData("articles", $oArticleList);
1259 
1260  // Process view data array through oxOutput processor
1261  $this->_processViewArray();
1262 
1263  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1264  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1265  $this->setBody($oSmarty->fetch($this->getConfig()->getTemplatePath($this->_sReminderMailTemplate, false)));
1266  $this->setAltBody("");
1267  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('STOCK_LOW'));
1268 
1269  $blSend = $this->send();
1270  }
1271 
1272  return $blSend;
1273  }
1274 
1283  public function sendWishlistMail($oParams)
1284  {
1285  $myConfig = $this->getConfig();
1286 
1287  $this->_clearMailer();
1288 
1289  // shop info
1290  $oShop = $this->_getShop();
1291 
1292  // mailer stuff
1293  $this->setFrom($oParams->send_email, $oParams->send_name);
1294  $this->setSMTP();
1295 
1296  // create messages
1297  $oSmarty = $this->_getSmarty();
1298  $this->setUser($oParams);
1299 
1300  // Process view data array through oxoutput processor
1301  $this->_processViewArray();
1302 
1303  $this->setBody($oSmarty->fetch($this->_sWishListTemplate));
1304  $this->setAltBody($oSmarty->fetch($this->_sWishListTemplatePlain));
1305  $this->setSubject($oParams->send_subject);
1306 
1307  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
1308  $this->setReplyTo($oParams->send_email, $oParams->send_name);
1309 
1310  return $this->send();
1311  }
1312 
1323  public function sendPriceAlarmNotification($aParams, $oAlarm, $sSubject = null)
1324  {
1325  $this->_clearMailer();
1326  $oShop = $this->_getShop();
1327 
1328  //set mail params (from, fromName, smtp)
1329  $this->_setMailParams($oShop);
1330 
1331  $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
1332 
1333  $oArticle = oxNew("oxarticle");
1334  //$oArticle->setSkipAbPrice( true );
1335  $oArticle->loadInLang($iAlarmLang, $aParams['aid']);
1336  $oLang = oxRegistry::getLang();
1337 
1338  // create messages
1339  $oSmarty = $this->_getSmarty();
1340  $this->setViewData("product", $oArticle);
1341  $this->setViewData("email", $aParams['email']);
1342  $this->setViewData("bidprice", $oLang->formatCurrency($oAlarm->oxpricealarm__oxprice->value, $oCur));
1343 
1344  // Process view data array through oxOutput processor
1345  $this->_processViewArray();
1346 
1347  $this->setRecipient($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1348  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('PRICE_ALERT_FOR_PRODUCT', $iAlarmLang) . " " . $oArticle->oxarticles__oxtitle->getRawValue());
1349  $this->setBody($oSmarty->fetch($this->_sOwnerPricealarmTemplate));
1350  $this->setFrom($aParams['email'], "");
1351  $this->setReplyTo($aParams['email'], "");
1352 
1353  return $this->send();
1354  }
1355 
1367  public function sendPricealarmToCustomer($sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null)
1368  {
1369  $this->_clearMailer();
1370 
1371  $oShop = $this->_getShop();
1372 
1373  if ($oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
1374  $oShop = oxNew("oxshop");
1375  $oShop->load($oAlarm->oxpricealarm__oxshopid->value);
1376  $this->setShop($oShop);
1377  }
1378 
1379  //set mail params (from, fromName, smtp)
1380  $this->_setMailParams($oShop);
1381 
1382  // create messages
1383  $oSmarty = $this->_getSmarty();
1384 
1385  $this->setViewData("product", $oAlarm->getArticle());
1386  $this->setViewData("oPriceAlarm", $oAlarm);
1387  $this->setViewData("bidprice", $oAlarm->getFProposedPrice());
1388  $this->setViewData("currency", $oAlarm->getPriceAlarmCurrency());
1389 
1390  // Process view data array through oxoutput processor
1391  $this->_processViewArray();
1392 
1393  $this->setRecipient($sRecipient, $sRecipient);
1394  $this->setSubject($oShop->oxshops__oxname->value);
1395 
1396  if ($sBody === null) {
1397  $sBody = $oSmarty->fetch($this->_sPricealamrCustomerTemplate);
1398  }
1399 
1400  $this->setBody($sBody);
1401 
1402  $this->addAddress($sRecipient, $sRecipient);
1403  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1404 
1405  if ($sReturnMailBody) {
1406  return $this->getBody();
1407  } else {
1408  return $this->send();
1409  }
1410  }
1411 
1421  protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
1422  {
1423  $sBody = $this->getBody();
1424  if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
1425 
1426  $oFileUtils = oxRegistry::get("oxUtilsFile");
1427  $blReSetBody = false;
1428 
1429  // preparing imput
1430  $sDynImageDir = $oFileUtils->normalizeDir($sDynImageDir);
1431  $sImageDir = $oFileUtils->normalizeDir($sImageDir);
1432  $sImageDirNoSSL = $oFileUtils->normalizeDir($sImageDirNoSSL);
1433 
1434  if (is_array($matches) && count($matches)) {
1435  $aImageCache = array();
1436  $myUtils = oxRegistry::getUtils();
1437  $myUtilsObject = oxUtilsObject::getInstance();
1438  $oImgGenerator = oxNew("oxDynImgGenerator");
1439 
1440  foreach ($matches as $aImage) {
1441 
1442  $image = $aImage[1];
1443  $sFileName = '';
1444  if (strpos($image, $sDynImageDir) === 0) {
1445  $sFileName = $oFileUtils->normalizeDir($sAbsDynImageDir) . str_replace($sDynImageDir, '', $image);
1446  } elseif (strpos($image, $sImageDir) === 0) {
1447  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDir, '', $image);
1448  } elseif (strpos($image, $sImageDirNoSSL) === 0) {
1449  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDirNoSSL, '', $image);
1450  }
1451 
1452  if ($sFileName && !@is_readable($sFileName)) {
1453  $sFileName = $oImgGenerator->getImagePath($sFileName);
1454  }
1455 
1456  if ($sFileName) {
1457  $sCId = '';
1458  if (isset($aImageCache[$sFileName]) && $aImageCache[$sFileName]) {
1459  $sCId = $aImageCache[$sFileName];
1460  } else {
1461  $sCId = $myUtilsObject->generateUID();
1462  $sMIME = $myUtils->oxMimeContentType($sFileName);
1463  if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
1464  if ($this->addEmbeddedImage($sFileName, $sCId, "image", "base64", $sMIME)) {
1465  $aImageCache[$sFileName] = $sCId;
1466  } else {
1467  $sCId = '';
1468  }
1469  }
1470  }
1471  if ($sCId && $sCId == $aImageCache[$sFileName]) {
1472  if ($sReplTag = str_replace($image, 'cid:' . $sCId, $aImage[0])) {
1473  $sBody = str_replace($aImage[0], $sReplTag, $sBody);
1474  $blReSetBody = true;
1475  }
1476  }
1477  }
1478  }
1479  }
1480 
1481  if ($blReSetBody) {
1482  $this->setBody($sBody);
1483  }
1484  }
1485  }
1486 
1492  public function setSubject($sSubject = null)
1493  {
1494  // A. HTML entities in subjects must be replaced
1495  $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>'), $sSubject);
1496 
1497  $this->set("Subject", $sSubject);
1498  }
1499 
1505  public function getSubject()
1506  {
1507  return $this->Subject;
1508  }
1509 
1517  public function setBody($sBody = null, $blClearSid = true)
1518  {
1519  if ($blClearSid) {
1520  $sBody = $this->_clearSidFromBody($sBody);
1521  }
1522 
1523  $this->set("Body", $sBody);
1524  }
1525 
1531  public function getBody()
1532  {
1533  return $this->Body;
1534  }
1535 
1543  public function setAltBody($sAltBody = null, $blClearSid = true)
1544  {
1545  if ($blClearSid) {
1546  $sAltBody = $this->_clearSidFromBody($sAltBody);
1547  }
1548 
1549  // A. alt body is used for plain text emails so we should eliminate HTML entities
1550  $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>'), $sAltBody);
1551 
1552  $this->set("AltBody", $sAltBody);
1553  }
1554 
1560  public function getAltBody()
1561  {
1562  return $this->AltBody;
1563  }
1564 
1571  public function setRecipient($sAddress = null, $sName = null)
1572  {
1573  try {
1574  if ($this->getConfig()->isUtf() && function_exists('idn_to_ascii') ) {
1575  $sAddress = idn_to_ascii($sAddress);
1576  }
1577 
1578  parent::AddAddress($sAddress, $sName);
1579 
1580  // copying values as original class does not allow to access recipients array
1581  $this->_aRecipients[] = array($sAddress, $sName);
1582  } catch (Exception $oEx) {
1583  }
1584  }
1585 
1593  public function getRecipient()
1594  {
1595  return $this->_aRecipients;
1596  }
1597 
1601  public function clearAllRecipients()
1602  {
1603  $this->_aRecipients = array();
1605  }
1606 
1616  public function setReplyTo($sEmail = null, $sName = null)
1617  {
1618  if (!oxRegistry::getUtils()->isValidEmail($sEmail)) {
1619  $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
1620  }
1621 
1622  $this->_aReplies[] = array($sEmail, $sName);
1623 
1624  try {
1625  parent::addReplyTo($sEmail, $sName);
1626  } catch (Exception $oEx) {
1627  }
1628  }
1629 
1635  public function getReplyTo()
1636  {
1637  return $this->_aReplies;
1638  }
1639 
1643  public function clearReplyTos()
1644  {
1645  $this->_aReplies = array();
1647  }
1648 
1655  public function setFrom($sFromAddress, $sFromName = null)
1656  {
1657  // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
1658  // this is simple but must work
1659  // Task #1532 field "From" in emails from shops
1660  $sFromAddress = substr($sFromAddress, 0, 150);
1661  $sFromName = substr($sFromName, 0, 150);
1662 
1663  try {
1664  parent::setFrom($sFromAddress, $sFromName);
1665  } catch (Exception $oEx) {
1666  }
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 
1776  public function addAttachment($sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream')
1777  {
1778  $this->_aAttachments[] = array($sAttPath, $sAttFile, $sEncoding, $sType);
1779  $blResult = false;
1780 
1781  try {
1782  $blResult = parent::addAttachment($sAttPath, $sAttFile, $sEncoding, $sType);
1783  } catch (Exception $oEx) {
1784  }
1785 
1786  return $blResult;
1787  }
1788 
1800  public function addEmbeddedImage($sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream')
1801  {
1802  $this->_aAttachments[] = array($sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid);
1803 
1804  return parent::addEmbeddedImage($sFullPath, $sCid, $sAttFile, $sEncoding, $sType);
1805  }
1806 
1812  public function getAttachments()
1813  {
1814  return $this->_aAttachments;
1815  }
1816 
1822  public function clearAttachments()
1823  {
1824  $this->_aAttachments = array();
1825 
1826  return parent::clearAttachments();
1827  }
1828 
1838  public function headerLine($sName, $sValue)
1839  {
1840  if (stripos($sName, 'X-') !== false) {
1841  return;
1842  }
1843 
1844  return parent::headerLine($sName, $sValue);
1845  }
1846 
1852  protected function _getUseInlineImages()
1853  {
1854  return $this->_blInlineImgEmail;
1855  }
1856 
1862  protected function _sendMailErrorMsg()
1863  {
1864  // build addresses
1865  $aRecipients = $this->getRecipient();
1866 
1867  $sOwnerMessage = "Error sending eMail(" . $this->getSubject() . ") to: \n\n";
1868 
1869  foreach ($aRecipients as $aEMail) {
1870  $sOwnerMessage .= $aEMail[0];
1871  $sOwnerMessage .= (!empty($aEMail[1])) ? ' (' . $aEMail[1] . ')' : '';
1872  $sOwnerMessage .= " \n ";
1873  }
1874  $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
1875 
1876  // shop info
1877  $oShop = $this->_getShop();
1878 
1879  $blRet = @mail($oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
1880 
1881  return $blRet;
1882  }
1883 
1893  protected function _addUserInfoOrderEMail($oOrder)
1894  {
1895  return $oOrder;
1896  }
1897 
1907  protected function _addUserRegisterEmail($oUser)
1908  {
1909  return $oUser;
1910  }
1911 
1921  protected function _addForgotPwdEmail($oShop)
1922  {
1923  return $oShop;
1924  }
1925 
1935  protected function _addNewsletterDbOptInMail($oUser)
1936  {
1937  return $oUser;
1938  }
1939 
1943  protected function _clearMailer()
1944  {
1945  $this->clearAllRecipients();
1946  $this->clearReplyTos();
1947  $this->clearAttachments();
1948 
1949  //workaround for phpmailer as it doesn't cleanup as it should
1950  $this->error_count = 0;
1951  $this->ErrorInfo = '';
1952  }
1953 
1959  protected function _setMailParams($oShop = null)
1960  {
1961  $this->_clearMailer();
1962 
1963  if (!$oShop) {
1964  $oShop = $this->_getShop();
1965  }
1966 
1967  $this->setFrom($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1968  $this->setSmtp($oShop);
1969  }
1970 
1980  protected function _getShop($iLangId = null, $iShopId = null)
1981  {
1982  if ($iLangId === null && $iShopId === null) {
1983  if (isset($this->_oShop)) {
1984  return $this->_oShop;
1985  } else {
1986  return $this->_oShop = $this->getConfig()->getActiveShop();
1987  }
1988  }
1989 
1990  $myConfig = $this->getConfig();
1991 
1992  $oShop = oxNew('oxShop');
1993  if ($iShopId !== null) {
1994  $oShop->setShopId($iShopId);
1995  }
1996  if ($iLangId !== null) {
1997  $oShop->setLanguage($iLangId);
1998  }
1999  $oShop->load($myConfig->getShopId());
2000 
2001  return $oShop;
2002  }
2003 
2010  protected function _setSmtpAuthInfo($sUserName = null, $sUserPassword = null)
2011  {
2012  $this->set("SMTPAuth", true);
2013  $this->set("Username", $sUserName);
2014  $this->set("Password", $sUserPassword);
2015  }
2016 
2022  protected function _setSmtpDebug($blDebug = null)
2023  {
2024  $this->set("SMTPDebug", $blDebug);
2025  }
2026 
2030  protected function _setMailerPluginDir()
2031  {
2032  $this->set("PluginDir", getShopBasePath() . "core/phpmailer/");
2033  }
2034 
2039  protected function _makeOutputProcessing()
2040  {
2041  $oOutput = oxNew("oxOutput");
2042  $this->setBody($oOutput->process($this->getBody(), "oxemail"));
2043  $this->setAltBody($oOutput->process($this->getAltBody(), "oxemail"));
2044  $oOutput->processEmail($this);
2045  }
2046 
2052  protected function _sendMail()
2053  {
2054  $blResult = false;
2055  try {
2056  $blResult = parent::send();
2057  } catch (Exception $oException) {
2058  $oEx = oxNew("oxException");
2059  $oEx->setMessage($oException->getMessage());
2060  $oEx->debugOut();
2061  if ($this->getConfig()->getConfigParam('iDebug') != 0) {
2062  throw $oEx;
2063  }
2064  }
2065 
2066  return $blResult;
2067  }
2068 
2069 
2073  protected function _processViewArray()
2074  {
2075  $oSmarty = $this->_getSmarty();
2076  $oOutputProcessor = oxNew("oxOutput");
2077 
2078  // processing all view data
2079  foreach ($this->_aViewData as $sKey => $sValue) {
2080  $oSmarty->assign($sKey, $sValue);
2081  }
2082 
2083  // processing assigned smarty variables
2084  $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
2085 
2086  foreach ($aNewSmartyArray as $key => $val) {
2087  $oSmarty->assign($key, $val);
2088  }
2089  }
2090 
2096  public function getCharset()
2097  {
2098  if (!$this->_sCharSet) {
2099  return oxRegistry::getLang()->translateString("charset");
2100  } else {
2101  return $this->CharSet;
2102  }
2103  }
2104 
2110  public function getShop()
2111  {
2112  return $this->_getShop();
2113  }
2114 
2120  public function setShop($oShop)
2121  {
2122  $this->_oShop = $oShop;
2123  }
2124 
2130  public function getViewConfig()
2131  {
2132  return $this->getConfig()->getActiveView()->getViewConfig();
2133  }
2134 
2140  public function getView()
2141  {
2142  return $this->getConfig()->getActiveView();
2143  }
2144 
2150  public function getCurrency()
2151  {
2152  $oConfig = oxRegistry::getConfig();
2153 
2154  return $oConfig->getActShopCurrencyObject();
2155  }
2156 
2163  public function setViewData($sKey, $sValue)
2164  {
2165  $this->_aViewData[$sKey] = $sValue;
2166  }
2167 
2173  public function getViewData()
2174  {
2175  return $this->_aViewData;
2176  }
2177 
2185  public function getViewDataItem($sKey)
2186  {
2187  if (isset($this->_aViewData[$sKey])) {
2188  return $this->_aViewData;
2189  }
2190  }
2191 
2197  public function setUser($oUser)
2198  {
2199  $this->_aViewData["oUser"] = $oUser;
2200  }
2201 
2207  public function getUser()
2208  {
2209  return $this->_aViewData["oUser"];
2210  }
2211 
2219  public function getOrderFileList($sOrderId)
2220  {
2221  $oOrderList = oxNew('oxOrderFileList');
2222  $oOrderList->loadOrderFiles($sOrderId);
2223 
2224  if (count($oOrderList) > 0) {
2225  return $oOrderList;
2226  }
2227 
2228  return false;
2229  }
2230 
2238  private function _clearSidFromBody($sAltBody)
2239  {
2240  return oxStr::getStr()->preg_replace('/(\?|&(amp;)?)(force_)?(admin_)?sid=[A-Z0-9\.]+/i', '\1shp=' . $this->getConfig()->getShopId(), $sAltBody);
2241  }
2242 }