|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
-
- namespace Controller;
-
- class Email {
-
- var $c = [];
- var $data = [];
- var $path = "";
-
- function __construct() {
-
- }
-
- function load_form_config($token) {
- $f3 = \Base::instance();
-
- $token_db = $f3->get('TEMP') . "CEform/";
- $db = new \DB\Jig($token_db,\DB\Jig::FORMAT_JSON);
- $formcall = new \DB\Jig\Mapper($db,'form_calls');
-
- $formcall->load(['@token = ?', $token]);
- $f3->config($formcall->form);
- $this->path = $formcall->path;
-
- return true;
- }
-
- function get_post_data() {
- $f3 = \Base::instance();
- $token = $f3->get('POST.xss-token');
- if (ctype_alnum( $token )) {
- if ($this->load_form_config($token)) {
-
- foreach ($f3->get('fields') as $field => $def) {
- $this->data['fields'][$field] = $f3->get('POST.'.$field);
- }
- $this->data['private'] = $f3->get('private');
-
- return true;
- } else {
- return false;
- }
- } else {
- // wrong xss-token supplied - malicous attac expected
- die;
- }
- }
-
- function send() {
- $f3 = \Base::instance();
-
- $this->get_post_data();
-
- $to = $this->data['private']['email'];
- $subject = $this->data['private']['subject'];
- $message = $this->data['fields']['message'];
-
- $c = $this->data['private']['emailconfig'];
-
- $template = substr($this->path . $this->data['private']['template'],10);
-
- $f3->set('fields', $this->data['fields']);
-
-
- $headers = [
- "MIME-Version"=>"1.0",
- "Content-type"=>"text/html",
- "From" => $c['from']
- ];
- //$c = $this->c;
- $smtp = new \SMTP(
- $c['host'],
- $c['port'],
- $c['scheme'],
- $c['user'],
- $c['pass'],
- );
-
- $smtp->set('To', $to);
- $smtp->set('Subject',$subject);
- foreach ($headers as $k=>$v) {
- $smtp->set($k,$v);
- }
-
- if ($smtp->send(\Template::instance()->render($template,'text/html'))) {
- # if(false) {
- $success = true;
- } else {
- $success = false;
- }
-
- if ($success) {
- $f3->reroute("/email/success");
- } else {
- #$f3->reroute("/email/error");
- echo \Template::instance()->render($template,'text/html');
- die;
- }
- }
- }
|