Bläddra i källkod

add email controller

master
Dom SP 3 år sedan
förälder
incheckning
74597662a4
1 ändrade filer med 101 tillägg och 0 borttagningar
  1. +101
    -0
      app/controller/email.php

+ 101
- 0
app/controller/email.php Visa fil

@@ -0,0 +1,101 @@
<?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;
}
}
}

Laddar…
Avbryt
Spara