2016-07-22 20:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once ('vn/web/json-request.php');
|
|
|
|
require_once ('libphp-phpmailer/PHPMailerAutoload.php');
|
|
|
|
|
|
|
|
use Vn\Lib;
|
|
|
|
|
|
|
|
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
|
|
|
];
|
|
|
|
|
2016-09-23 22:47:34 +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'];
|
|
|
|
unset ($_SESSION['captcha']);
|
|
|
|
|
2016-09-19 06:40:18 +00:00
|
|
|
if ($_REQUEST['captcha'] !== $lastCaptcha)
|
2016-07-22 20:00:27 +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
|
|
|
|
//$db->queryFromFile (__DIR__.'/contact', $_REQUEST);
|
|
|
|
//$customerId = $db->getValue ('SELECT @id');
|
|
|
|
|
|
|
|
$conf = $db->getRow (
|
|
|
|
'SELECT m.host, m.port, m.secure, m.sender, m.user, m.password, c.recipient
|
|
|
|
FROM mail_config m JOIN contact c'
|
|
|
|
);
|
|
|
|
|
|
|
|
$mail = new PHPMailer ();
|
|
|
|
$mail->isSMTP ();
|
|
|
|
$mail->Host = $conf['host'];
|
|
|
|
|
|
|
|
if (!empty ($conf['user']))
|
|
|
|
{
|
|
|
|
$mail->SMTPAuth = TRUE;
|
|
|
|
$mail->Username = $conf['user'];
|
|
|
|
$mail->Password = base64_decode ($conf['password']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$mail->SMTPAuth = FALSE;
|
|
|
|
|
|
|
|
if ($conf['secure'])
|
|
|
|
{
|
|
|
|
$mail->SMTPSecure = 'ssl';
|
|
|
|
$mail->Port = 465;
|
|
|
|
}
|
|
|
|
|
|
|
|
$mail->setFrom ($conf['sender'], 'Web');
|
|
|
|
$mail->addAddress ($conf['recipient']);
|
|
|
|
$mail->isHTML (TRUE);
|
|
|
|
$mail->Subject = s('New customer request');
|
|
|
|
$mail->Body = '<pre>'. print_r ($_REQUEST, TRUE) .'</pre>';
|
|
|
|
|
|
|
|
if (!$mail->send ())
|
|
|
|
throw new Exception ($mail->ErrorInfo);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|