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.

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