mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

105 lines
2.6KB

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