email.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreSamples Samples
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section email Send Email
  12. */
  13. $aPathInfo = pathinfo(__FILE__);
  14. require_once ($aPathInfo['dirname'] . '/../inc/header.inc.php');
  15. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  16. $oTemplate = BxDolTemplate::getInstance();
  17. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  18. $oTemplate->setPageHeader ("Send Email Example");
  19. $oTemplate->setPageContent ('page_main_code', PageCompMainCode());
  20. $oTemplate->getPageCode();
  21. /**
  22. * page code function
  23. */
  24. function PageCompMainCode()
  25. {
  26. ob_start();
  27. $oAccount = BxDolAccount::getInstance();
  28. $aAccountInfo = $oAccount ? $oAccount->getInfo() : false;
  29. if (!$aAccountInfo)
  30. return DesignBoxContent("Send Email example", 'Please login first', BX_DB_PADDING_DEF);
  31. echo "<h2>Account info</h2>";
  32. echo "Email: " . $aAccountInfo['email'] . '<br />';
  33. echo "Email Confirmed: " . ($aAccountInfo['email_confirmed'] ? 'yes' : 'no') . '<br />';
  34. echo "Receive site updates: " . ($aAccountInfo['receive_updates'] ? 'yes' : 'no') . '<br />';
  35. echo "Receive site newsletters: " . ($aAccountInfo['receive_news'] ? 'yes' : 'no') . '<br />';
  36. echo "Site emails are sent from: " . getParam('site_email_notify') . '<br />';
  37. $a = array (
  38. 'sys' => array (
  39. 'title' => "Send me system email",
  40. 'type' => BX_EMAIL_SYSTEM,
  41. 'subj' => 'System Email',
  42. 'body' => 'This is system email <br /> {unsubscribe}',
  43. ),
  44. 'notif' => array (
  45. 'title' => "Send me notification",
  46. 'type' => BX_EMAIL_NOTIFY,
  47. 'subj' => 'Notification Email',
  48. 'body' => 'This is notification email<br /> {unsubscribe}',
  49. ),
  50. 'mass' => array (
  51. 'title' => "Send me bulk email",
  52. 'type' => BX_EMAIL_MASS,
  53. 'subj' => 'Bulk Email',
  54. 'body' => 'This is bulk email<br /> {unsubscribe}',
  55. ),
  56. );
  57. $sSendMail = bx_get('send');
  58. if ($sSendMail && isset($a[$sSendMail])) {
  59. echo "<h2>Send Email Result</h2>";
  60. $r = $a[$sSendMail];
  61. if (sendMail($aAccountInfo['email'], $r['subj'], $r['body'], 0, array(), $r['type']))
  62. echo MsgBox($r['subj'] . ' - successfully sent');
  63. else
  64. echo MsgBox($r['subj'] . ' - sent failed');
  65. }
  66. echo "<h2>Send email</h2>";
  67. foreach ($a as $k => $r) {
  68. echo '<a href="samples/email.php?send=' . $k . '">' . $r['title'] . '</a><br />';
  69. }
  70. return DesignBoxContent("Send Email Example", ob_get_clean(), BX_DB_PADDING_DEF);
  71. }
  72. /** @} */