/var/www/(Del)gepgroup.hk/contact_us_ajax.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
$without_session_start 
true;
require_once( 
realpath(dirname(__FILE__)) . '/common/config.php');

// check is post
if (strtoupper($_SERVER['REQUEST_METHOD']) != 'POST')
{
    echo 
'{ "result":"Failure" }';
    exit;
}

// reCAPTCHA
$api_param = array(
    
'secret' => '6LfEmgETAAAAABDIgFhwd1lYr3wO5cZFNzxbvs2X',
    
'remoteip' => $_SERVER['REMOTE_ADDR'],
    
'response' => $_POST['g-recaptcha-response']
);

$api_url 'https://www.google.com/recaptcha/api/siteverify?'http_build_query($api_param);

$json file_get_contents($api_url);
$response json_decode($json);
// echo $response->access_token;
if ( $response->success !== true )
{
    echo 
'{ "result":"Failure" }';
    exit;
}

//ini_set('display_errors', 1);
//error_reporting(E_ALL);

// Create contact us log
$log = new LogContactUsEmail(array(
    
'ip_address' => $_SERVER["REMOTE_ADDR"],
));
$log->safe_set_attributes($_POST);

// Save log
$is_saved $log->save();

// to
$to_emails = array();
$contact_us_email_to Miscellaneous::key('contact_us_email_to');
if (!empty(
$contact_us_email_to->value)){
    
$lists explode(','$contact_us_email_to->value);
    foreach(
$lists as $email){
        
$to_emails[] = trim($email);
    }
}

// body
ob_start();

?><div><pre>You have a message via GEP Group Website contact us form.

The following information are the details,

Name: <?=$log->name?>

Email: <?=$log->email?>

Subject: <?=$log->subject?>

Message:
<?=$log->message?>

--- End of Description  --</pre></div><?php

$body 
nl2br(ob_get_contents());
ob_end_clean();

// Send email
require_once( realpath(dirname(__FILE__)) . '/function_mail.php');
$x_mail create_mail();
$x_mail->From $log->email;
$x_mail->FromName $log->name;
foreach (
$to_emails as $to_email)
$x_mail->AddAddress($to_email);
$x_mail->Subject "Website Enquiry - gepgroup.hk";
$x_mail->Body $body;
$is_send $x_mail->Send();

if (
$is_saved && $is_send) {
    echo 
'{ "result":"Success" }';
} else {
    
$errors = array();
    if (!
$is_send)
        
$errors[] = '"Send mail"';
    if (!
$is_saved)
        
$errors[] = '"Save mail"';
    
$reason implode(','$errors);

    echo 
'{ "result":"Failure","reason": [' $reason '] }';
}
?>