test.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * A test page for theme developer to view the layout of an email notification
  4. */
  5. elgg_admin_gatekeeper();
  6. $user = elgg_get_logged_in_user_entity();
  7. $site = elgg_get_site_entity();
  8. $subject = elgg_echo("useradd:subject");
  9. $plain_message = elgg_echo("useradd:body", array(
  10. $user->name,
  11. $site->name,
  12. $site->url,
  13. $user->username,
  14. 'test123',
  15. ));
  16. $html_message = elgg_view("html_email_handler/notification/body", array(
  17. "subject" => $subject,
  18. "body" => $plain_message,
  19. "recipient" => $user
  20. ));
  21. $html_message = html_email_handler_css_inliner($html_message);
  22. $html_message_ext = html_email_handler_normalize_urls($html_message);
  23. $html_message_ext = html_email_handler_base64_encode_images($html_message_ext);
  24. echo $html_message_ext;
  25. if (get_input("mail")) {
  26. // Test sending a basic HTML mail
  27. $options = array(
  28. 'to' => $user->email,
  29. 'subject' => $subject,
  30. 'body' => $plain_message,
  31. 'recipient' => $user,
  32. 'attachments' => array(
  33. array(
  34. 'filepath' => dirname(__DIR__) . '/manifest.xml',
  35. ),
  36. ),
  37. );
  38. html_email_handler_send_email($options);
  39. // Test sending attachments through notify_user()
  40. $to = $user->guid;
  41. $from = $site->guid;
  42. $subject = 'Notification test';
  43. $message = 'This notification has been sent using notify_user() and it should have an attachment.';
  44. $params = array(
  45. 'recipient' => $user,
  46. 'attachments' => array(
  47. array(
  48. 'filepath' => dirname(__DIR__) . '/manifest.xml',
  49. )
  50. )
  51. );
  52. notify_user($to, $from, $subject, $message, $params, array('email'));
  53. }