325 lines
4.5 KiB
PHP
325 lines
4.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
|
|
* Sets error header and json error message response.
|
|
|
|
*
|
|
|
|
* @param String $messsage error message of response
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function errorResponse ($messsage) {
|
|
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
|
|
die(json_encode(array('message' => $messsage)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pulls posted values for all fields in $fields_req array.
|
|
|
|
* If a required field does not have a value, an error response is given.
|
|
|
|
*/
|
|
|
|
function constructMessageBody () {
|
|
|
|
$fields_req = array("name" => true, "email" => true, "message" => true);
|
|
|
|
$message_body = "";
|
|
|
|
foreach ($fields_req as $name => $required) {
|
|
|
|
$postedValue = $_POST[$name];
|
|
|
|
if ($required && empty($postedValue)) {
|
|
|
|
errorResponse("$name is empty.");
|
|
|
|
}
|
|
|
|
// else {
|
|
|
|
// $message_body .= ucfirst($name) . ": " . $postedValue . "\n";
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlhead .= "<html><head>\r\n";
|
|
|
|
$htmlhead .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n";
|
|
|
|
$htmlhead .= "</head>\r\n";
|
|
|
|
$htmlhead .= "<style type=\"text/css\">";
|
|
|
|
$htmlhead .= "body
|
|
|
|
{
|
|
|
|
margin: 0px;
|
|
|
|
cursor: default;
|
|
|
|
font-family: \"Segoe UI\", Sans-Serif;
|
|
|
|
font-size: 12pt;
|
|
|
|
}
|
|
|
|
h1
|
|
|
|
{
|
|
|
|
background-color: #ffc153;
|
|
|
|
font-size: 14pt;
|
|
|
|
font-weight: normal;
|
|
|
|
padding: 3px 8px;
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#lastupdate
|
|
|
|
{
|
|
|
|
padding: 3px 8px;
|
|
|
|
color: #AAA;
|
|
|
|
}
|
|
|
|
|
|
|
|
#todolist
|
|
|
|
{
|
|
|
|
background: #fff;
|
|
|
|
width: 100%;
|
|
|
|
border-collapse: collapse;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
#todolist th
|
|
|
|
{
|
|
|
|
font-weight: normal;
|
|
|
|
background-color: #ffc153;
|
|
|
|
padding: 4px 8px;
|
|
|
|
border-bottom: 1px solid #F93;
|
|
|
|
border-top: 1px solid #F93;
|
|
|
|
}
|
|
|
|
#todolist th:first-child
|
|
|
|
{
|
|
|
|
padding-left: 25px;
|
|
|
|
}
|
|
|
|
#todolist td
|
|
|
|
{
|
|
|
|
border-bottom: 1px solid #F93;
|
|
|
|
padding: 3px 8px;
|
|
|
|
}
|
|
|
|
#todolist tbody tr.entryrow td:first-child
|
|
|
|
{
|
|
|
|
padding-left: 25px;
|
|
|
|
}
|
|
|
|
#todolist tbody tr.entryrow:hover td
|
|
|
|
{
|
|
|
|
background-color: #A7CDF0;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
#todolist tbody tr.unseen td
|
|
|
|
{
|
|
|
|
font-weight:bold;
|
|
|
|
}
|
|
|
|
#todolist tbody tr.folderheader td
|
|
|
|
{
|
|
|
|
padding: 20px 8px 3px 8px;
|
|
|
|
font-weight:bold;
|
|
|
|
}";
|
|
|
|
$htmlhead .= " </style>\r\n";
|
|
|
|
$htmlhead .= "<body>\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$message_body =$htmlhead."<h1>Új érdeklődés / ajánlatkérés</h1><br>
|
|
|
|
Feladó neve: <strong>".$_POST['name']."</strong><br>\n".
|
|
|
|
"Email címe: <strong>".$_POST['email']."</strong><br>\n".
|
|
|
|
"Telefon: <strong>".$_POST['phone']."</strong><br><br>\n".
|
|
|
|
"Szolgáltatás típusa: <strong>".$_POST['reason']."</strong><br><br>\n".
|
|
|
|
"<u>Üzenet szövege: </u><br>\n".$_POST['message']."\n";
|
|
|
|
|
|
|
|
$message_body .= "</body>\r\n";
|
|
|
|
$message_body .= "</html>\r\n";
|
|
|
|
|
|
|
|
return $message_body;
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-type: application/json');
|
|
|
|
|
|
|
|
//do Captcha check, make sure the submitter is not a robot:)...
|
|
|
|
$url = 'https://www.google.com/recaptcha/api/siteverify';
|
|
|
|
$opts = array('http' =>
|
|
|
|
array(
|
|
|
|
'method' => 'POST',
|
|
|
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
|
|
|
'content' => http_build_query(array('secret' => '6LeT5goTAAAAAGWeVhyUJSoItToTNpUCIf8mwu4-', 'response' => $_POST["g-recaptcha-response"]))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$context = stream_context_create($opts);
|
|
|
|
$result = json_decode(file_get_contents($url, false, $context, -1, 40000));
|
|
|
|
|
|
|
|
if (!$result->success) {
|
|
|
|
errorResponse('reCAPTCHA ellenörzési hiba! Error codes: ' . join(', ', $result->{"error-codes"}));
|
|
|
|
}
|
|
|
|
//attempt to send email
|
|
|
|
$messageBody = constructMessageBody();
|
|
|
|
require './vender/php_mailer/PHPMailerAutoload.php';
|
|
|
|
$mail = new PHPMailer;
|
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
$mail->IsHTML(true);
|
|
|
|
//$mail->isSMTP();
|
|
|
|
//$mail->Host = 'mail.maxer.hu';
|
|
|
|
//$mail->SMTPAuth = true;
|
|
|
|
//$mail->Username = 'mail@sys.co.hu';
|
|
|
|
//$mail->Password = 'titok123';
|
|
|
|
//$mail->SMTPSecure = '';
|
|
|
|
//$mail->Port = 587;
|
|
|
|
|
|
|
|
$mail->setFrom('kapcsolat@skyflytravel.hu');
|
|
|
|
$mail->addAddress('info@skyflytravel.hu');
|
|
|
|
|
|
|
|
$mail->Subject = 'Új ajánlatkérés, '.$_POST['reason'];
|
|
|
|
$mail->Body = $messageBody;
|
|
|
|
|
|
|
|
|
|
|
|
//try to send the message
|
|
|
|
if($mail->send()) {
|
|
|
|
echo json_encode(array('message' => 'Az üzenetét sikeresen elküldtük. Munkatársunk hamarosan felveszi önnel a kapcsolatot.'));
|
|
|
|
} else {
|
|
|
|
errorResponse('HIBA történ az üzenet küldése közben: ' . $mail->ErrorInfo);
|
|
|
|
}
|
|
|
|
?>
|
|
|