hedera-web/rest/client/contact.php

66 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-22 20:00:27 +00:00
<?php
require_once('libphp-phpmailer/autoload.php');
2016-07-22 20:00:27 +00:00
use Vn\Lib;
2018-05-23 10:14:20 +00:00
class Contact extends Vn\Web\JsonRequest {
2016-09-06 14:25:02 +00:00
const PARAMS = [
'name'
,'pc'
,'phone'
,'email'
,'message'
2016-09-19 06:40:18 +00:00
,'captcha'
2016-09-06 14:25:02 +00:00
];
2018-05-23 10:14:20 +00:00
function run($db) {
2016-07-22 20:00:27 +00:00
// Checks the antispam code
2016-08-23 13:15:19 +00:00
2016-07-22 20:00:27 +00:00
$lastCaptcha = $_SESSION['captcha'];
2018-05-23 10:14:20 +00:00
unset($_SESSION['captcha']);
2016-07-22 20:00:27 +00:00
2016-09-19 06:40:18 +00:00
if ($_REQUEST['captcha'] !== $lastCaptcha)
2018-05-23 10:14:20 +00:00
throw new Lib\UserException (s('Wrong captcha'), 'wrongCaptcha');
2016-08-23 13:15:19 +00:00
2016-07-22 20:00:27 +00:00
// Sends the mail
// TODO: Change form fields
2018-05-23 10:14:20 +00:00
//$db->queryFromFile(__DIR__.'/contact', $_REQUEST);
//$customerId = $db->getValue('SELECT @id');
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
$conf = $db->getObject(
2016-07-22 20:00:27 +00:00
'SELECT m.host, m.port, m.secure, m.sender, m.user, m.password, c.recipient
2017-12-20 11:34:04 +00:00
FROM mailConfig m JOIN contact c'
2016-07-22 20:00:27 +00:00
);
2020-01-23 13:05:58 +00:00
$mail = new \PHPMailer();
2018-05-23 10:14:20 +00:00
$mail->isSMTP();
2017-12-20 11:34:04 +00:00
$mail->Host = $conf->host;
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
if (!empty($conf->user)) {
2016-07-22 20:00:27 +00:00
$mail->SMTPAuth = TRUE;
2017-12-20 11:34:04 +00:00
$mail->Username = $conf->user;
2018-05-23 10:14:20 +00:00
$mail->Password = base64_decode($conf->password);
2018-05-23 11:09:55 +00:00
} else
2016-07-22 20:00:27 +00:00
$mail->SMTPAuth = FALSE;
2018-05-23 10:14:20 +00:00
if ($conf->secure) {
2016-07-22 20:00:27 +00:00
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
}
2018-05-23 10:14:20 +00:00
$mail->setFrom($conf->sender, 'Web');
$mail->addAddress($conf->recipient);
$mail->isHTML(TRUE);
2016-07-22 20:00:27 +00:00
$mail->Subject = s('New customer request');
2018-05-23 10:14:20 +00:00
$mail->Body = '<pre>'. print_r($_REQUEST, TRUE) .'</pre>';
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
if (!$mail->send())
throw new Exception ($mail->ErrorInfo);
2016-07-22 20:00:27 +00:00
return TRUE;
}
}