OXID eShop CE  4.9.6
 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  parent::AddAddress($sAddress, $sName);
1575 
1576  // copying values as original class does not allow to access recipients array
1577  $this->_aRecipients[] = array($sAddress, $sName);
1578  } catch (Exception $oEx) {
1579  }
1580  }
1581 
1589  public function getRecipient()
1590  {
1591  return $this->_aRecipients;
1592  }
1593 
1597  public function clearAllRecipients()
1598  {
1599  $this->_aRecipients = array();
1601  }
1602 
1612  public function setReplyTo($sEmail = null, $sName = null)
1613  {
1614  if (!oxRegistry::getUtils()->isValidEmail($sEmail)) {
1615  $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
1616  }
1617 
1618  $this->_aReplies[] = array($sEmail, $sName);
1619 
1620  try {
1621  parent::addReplyTo($sEmail, $sName);
1622  } catch (Exception $oEx) {
1623  }
1624  }
1625 
1631  public function getReplyTo()
1632  {
1633  return $this->_aReplies;
1634  }
1635 
1639  public function clearReplyTos()
1640  {
1641  $this->_aReplies = array();
1643  }
1644 
1651  public function setFrom($sFromAddress, $sFromName = null)
1652  {
1653  // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
1654  // this is simple but must work
1655  // Task #1532 field "From" in emails from shops
1656  $sFromAddress = substr($sFromAddress, 0, 150);
1657  $sFromName = substr($sFromName, 0, 150);
1658 
1659  try {
1660  parent::setFrom($sFromAddress, $sFromName);
1661  } catch (Exception $oEx) {
1662  }
1663  }
1664 
1670  public function getFrom()
1671  {
1672  return $this->From;
1673  }
1674 
1680  public function getFromName()
1681  {
1682  return $this->FromName;
1683  }
1684 
1691  public function setCharSet($sCharSet = null)
1692  {
1693  if ($sCharSet) {
1694  $this->_sCharSet = $sCharSet;
1695  } else {
1696  $this->_sCharSet = oxRegistry::getLang()->translateString("charset");
1697  }
1698  $this->set("CharSet", $this->_sCharSet);
1699  }
1700 
1706  public function setMailer($sMailer = null)
1707  {
1708  $this->set("Mailer", $sMailer);
1709  }
1710 
1716  public function getMailer()
1717  {
1718  return $this->Mailer;
1719  }
1720 
1726  public function setHost($sHost = null)
1727  {
1728  $this->set("Host", $sHost);
1729  }
1730 
1736  public function getErrorInfo()
1737  {
1738  return $this->ErrorInfo;
1739  }
1740 
1747  public function setMailWordWrap($iWordWrap = null)
1748  {
1749  $this->set("WordWrap", $iWordWrap);
1750  }
1751 
1757  public function setUseInlineImages($blUseImages = null)
1758  {
1759  $this->_blInlineImgEmail = $blUseImages;
1760  }
1761 
1772  public function addAttachment($sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream')
1773  {
1774  $this->_aAttachments[] = array($sAttPath, $sAttFile, $sEncoding, $sType);
1775  $blResult = false;
1776 
1777  try {
1778  $blResult = parent::addAttachment($sAttPath, $sAttFile, $sEncoding, $sType);
1779  } catch (Exception $oEx) {
1780  }
1781 
1782  return $blResult;
1783  }
1784 
1796  public function addEmbeddedImage($sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream')
1797  {
1798  $this->_aAttachments[] = array($sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid);
1799 
1800  return parent::addEmbeddedImage($sFullPath, $sCid, $sAttFile, $sEncoding, $sType);
1801  }
1802 
1808  public function getAttachments()
1809  {
1810  return $this->_aAttachments;
1811  }
1812 
1818  public function clearAttachments()
1819  {
1820  $this->_aAttachments = array();
1821 
1822  return parent::clearAttachments();
1823  }
1824 
1834  public function headerLine($sName, $sValue)
1835  {
1836  if (stripos($sName, 'X-') !== false) {
1837  return;
1838  }
1839 
1840  return parent::headerLine($sName, $sValue);
1841  }
1842 
1848  protected function _getUseInlineImages()
1849  {
1850  return $this->_blInlineImgEmail;
1851  }
1852 
1858  protected function _sendMailErrorMsg()
1859  {
1860  // build addresses
1861  $aRecipients = $this->getRecipient();
1862 
1863  $sOwnerMessage = "Error sending eMail(" . $this->getSubject() . ") to: \n\n";
1864 
1865  foreach ($aRecipients as $aEMail) {
1866  $sOwnerMessage .= $aEMail[0];
1867  $sOwnerMessage .= (!empty($aEMail[1])) ? ' (' . $aEMail[1] . ')' : '';
1868  $sOwnerMessage .= " \n ";
1869  }
1870  $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
1871 
1872  // shop info
1873  $oShop = $this->_getShop();
1874 
1875  $blRet = @mail($oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
1876 
1877  return $blRet;
1878  }
1879 
1889  protected function _addUserInfoOrderEMail($oOrder)
1890  {
1891  return $oOrder;
1892  }
1893 
1903  protected function _addUserRegisterEmail($oUser)
1904  {
1905  return $oUser;
1906  }
1907 
1917  protected function _addForgotPwdEmail($oShop)
1918  {
1919  return $oShop;
1920  }
1921 
1931  protected function _addNewsletterDbOptInMail($oUser)
1932  {
1933  return $oUser;
1934  }
1935 
1939  protected function _clearMailer()
1940  {
1941  $this->clearAllRecipients();
1942  $this->clearReplyTos();
1943  $this->clearAttachments();
1944 
1945  //workaround for phpmailer as it doesn't cleanup as it should
1946  $this->error_count = 0;
1947  $this->ErrorInfo = '';
1948  }
1949 
1955  protected function _setMailParams($oShop = null)
1956  {
1957  $this->_clearMailer();
1958 
1959  if (!$oShop) {
1960  $oShop = $this->_getShop();
1961  }
1962 
1963  $this->setFrom($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1964  $this->setSmtp($oShop);
1965  }
1966 
1976  protected function _getShop($iLangId = null, $iShopId = null)
1977  {
1978  if ($iLangId === null && $iShopId === null) {
1979  if (isset($this->_oShop)) {
1980  return $this->_oShop;
1981  } else {
1982  return $this->_oShop = $this->getConfig()->getActiveShop();
1983  }
1984  }
1985 
1986  $myConfig = $this->getConfig();
1987 
1988  $oShop = oxNew('oxShop');
1989  if ($iShopId !== null) {
1990  $oShop->setShopId($iShopId);
1991  }
1992  if ($iLangId !== null) {
1993  $oShop->setLanguage($iLangId);
1994  }
1995  $oShop->load($myConfig->getShopId());
1996 
1997  return $oShop;
1998  }
1999 
2006  protected function _setSmtpAuthInfo($sUserName = null, $sUserPassword = null)
2007  {
2008  $this->set("SMTPAuth", true);
2009  $this->set("Username", $sUserName);
2010  $this->set("Password", $sUserPassword);
2011  }
2012 
2018  protected function _setSmtpDebug($blDebug = null)
2019  {
2020  $this->set("SMTPDebug", $blDebug);
2021  }
2022 
2026  protected function _setMailerPluginDir()
2027  {
2028  $this->set("PluginDir", getShopBasePath() . "core/phpmailer/");
2029  }
2030 
2035  protected function _makeOutputProcessing()
2036  {
2037  $oOutput = oxNew("oxOutput");
2038  $this->setBody($oOutput->process($this->getBody(), "oxemail"));
2039  $this->setAltBody($oOutput->process($this->getAltBody(), "oxemail"));
2040  $oOutput->processEmail($this);
2041  }
2042 
2048  protected function _sendMail()
2049  {
2050  $blResult = false;
2051  try {
2052  $blResult = parent::send();
2053  } catch (Exception $oException) {
2054  $oEx = oxNew("oxException");
2055  $oEx->setMessage($oException->getMessage());
2056  $oEx->debugOut();
2057  if ($this->getConfig()->getConfigParam('iDebug') != 0) {
2058  throw $oEx;
2059  }
2060  }
2061 
2062  return $blResult;
2063  }
2064 
2065 
2069  protected function _processViewArray()
2070  {
2071  $oSmarty = $this->_getSmarty();
2072  $oOutputProcessor = oxNew("oxOutput");
2073 
2074  // processing all view data
2075  foreach ($this->_aViewData as $sKey => $sValue) {
2076  $oSmarty->assign($sKey, $sValue);
2077  }
2078 
2079  // processing assigned smarty variables
2080  $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
2081 
2082  foreach ($aNewSmartyArray as $key => $val) {
2083  $oSmarty->assign($key, $val);
2084  }
2085  }
2086 
2092  public function getCharset()
2093  {
2094  if (!$this->_sCharSet) {
2095  return oxRegistry::getLang()->translateString("charset");
2096  } else {
2097  return $this->CharSet;
2098  }
2099  }
2100 
2106  public function getShop()
2107  {
2108  return $this->_getShop();
2109  }
2110 
2116  public function setShop($oShop)
2117  {
2118  $this->_oShop = $oShop;
2119  }
2120 
2126  public function getViewConfig()
2127  {
2128  return $this->getConfig()->getActiveView()->getViewConfig();
2129  }
2130 
2136  public function getView()
2137  {
2138  return $this->getConfig()->getActiveView();
2139  }
2140 
2146  public function getCurrency()
2147  {
2148  $oConfig = oxRegistry::getConfig();
2149 
2150  return $oConfig->getActShopCurrencyObject();
2151  }
2152 
2159  public function setViewData($sKey, $sValue)
2160  {
2161  $this->_aViewData[$sKey] = $sValue;
2162  }
2163 
2169  public function getViewData()
2170  {
2171  return $this->_aViewData;
2172  }
2173 
2181  public function getViewDataItem($sKey)
2182  {
2183  if (isset($this->_aViewData[$sKey])) {
2184  return $this->_aViewData;
2185  }
2186  }
2187 
2193  public function setUser($oUser)
2194  {
2195  $this->_aViewData["oUser"] = $oUser;
2196  }
2197 
2203  public function getUser()
2204  {
2205  return $this->_aViewData["oUser"];
2206  }
2207 
2215  public function getOrderFileList($sOrderId)
2216  {
2217  $oOrderList = oxNew('oxOrderFileList');
2218  $oOrderList->loadOrderFiles($sOrderId);
2219 
2220  if (count($oOrderList) > 0) {
2221  return $oOrderList;
2222  }
2223 
2224  return false;
2225  }
2226 
2234  private function _clearSidFromBody($sAltBody)
2235  {
2236  return oxStr::getStr()->preg_replace('/(\?|&(amp;)?)(force_)?(admin_)?sid=[A-Z0-9\.]+/i', '\1shp=' . $this->getConfig()->getShopId(), $sAltBody);
2237  }
2238 }