mostly filebased Content Presentation System
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

102 lines
2.5KB

  1. <?php
  2. namespace Controller;
  3. class Email {
  4. var $c = [];
  5. var $data = [];
  6. var $path = "";
  7. function __construct() {
  8. }
  9. function load_form_config($token) {
  10. $f3 = \Base::instance();
  11. $token_db = $f3->get('TEMP') . "CEform/";
  12. $db = new \DB\Jig($token_db,\DB\Jig::FORMAT_JSON);
  13. $formcall = new \DB\Jig\Mapper($db,'form_calls');
  14. $formcall->load(['@token = ?', $token]);
  15. $f3->config($formcall->form);
  16. $this->path = $formcall->path;
  17. return true;
  18. }
  19. function get_post_data() {
  20. $f3 = \Base::instance();
  21. $token = $f3->get('POST.xss-token');
  22. if (ctype_alnum( $token )) {
  23. if ($this->load_form_config($token)) {
  24. foreach ($f3->get('fields') as $field => $def) {
  25. $this->data['fields'][$field] = $f3->get('POST.'.$field);
  26. }
  27. $this->data['private'] = $f3->get('private');
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. } else {
  33. // wrong xss-token supplied - malicous attac expected
  34. die;
  35. }
  36. }
  37. function send() {
  38. $f3 = \Base::instance();
  39. $this->get_post_data();
  40. $to = $this->data['private']['email'];
  41. $subject = $this->data['private']['subject'];
  42. $message = $this->data['fields']['message'];
  43. $c = $this->data['private']['emailconfig'];
  44. $template = substr($this->path . $this->data['private']['template'],10);
  45. $f3->set('fields', $this->data['fields']);
  46. $headers = [
  47. "MIME-Version"=>"1.0",
  48. "Content-type"=>"text/html",
  49. "From" => $c['from']
  50. ];
  51. //$c = $this->c;
  52. $smtp = new \SMTP(
  53. $c['host'],
  54. $c['port'],
  55. $c['scheme'],
  56. $c['user'],
  57. $c['pass'],
  58. );
  59. $smtp->set('To', $to);
  60. $smtp->set('Subject',$subject);
  61. foreach ($headers as $k=>$v) {
  62. $smtp->set($k,$v);
  63. }
  64. if ($smtp->send(\Template::instance()->render($template,'text/html'))) {
  65. # if(false) {
  66. $success = true;
  67. } else {
  68. $success = false;
  69. }
  70. if ($success) {
  71. $f3->reroute("/email/success");
  72. } else {
  73. #$f3->reroute("/email/error");
  74. echo \Template::instance()->render($template,'text/html');
  75. die;
  76. }
  77. }
  78. }