/var/www/hkosl.com/innoutstorage2019/tc/contactus_post.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
    
require_once('../webadmin/basic_info.php');

    
$message "";
    if (empty(
$_POST["template-contactform-name"])) {
        
$message .= "請輸入你的姓名。\\n\\n";
    }

    if (!empty(
$_POST["template-contactform-phone"]) && !is_numeric($_POST["template-contactform-phone"])) {
        
$message .= "請輸入你的電話。\\n\\n";
    }

    if (empty(
$_POST["template-contactform-email"])) {
        
$message .= "請輸入你的電郵。\\n\\n";
    } else {
        if (!
filter_var($_POST["template-contactform-email"], FILTER_VALIDATE_EMAIL)) {
            
$message .= "請輸入正確的電郵格式.\\n\\n";
        }
    }

    if (empty(
$_POST["template-contactform-message"])) {
        
$message .= "請輸入你的訊息。\\n\\n";
    }

    if (empty(
$_POST["g-recaptcha-response"])) {
        
$message .= "請進行驗證。\\n\\n";
    }else{
        
$url "https://www.google.com/recaptcha/api/siteverify";
        
$post_data = array("secret" => $google_recaptcha_secret_key"response" => $_POST["g-recaptcha-response"]);
        
$result call_curl($url$post_data1);
        
$result_array json_decode($resulttrue);
        if(!
$result_array["success"]){
            
$message .= "驗證無效。\\n\\n";
        }
    }


    if (!empty(
$message)) {
        echo 
"<script>alert('" $message "'); history.back(); </script>";
        exit;
    }

    
//insert enquiry into db
    
$data = array(
        
"user_name"  => $_POST["template-contactform-name"],
        
"phone"      => $_POST["template-contactform-phone"],
        
"email"      => $_POST["template-contactform-email"],
        
"content"    => $_POST["template-contactform-message"],
        
"createdate" => $nowdate
    
);

    
$result insert_record("enquiry"$data);

    
//send email
    
$email_subject "Online Enquiry";

    
//email content to customer
    
ob_start();

?>
    <html>
    <head>
        <META name=GENERATOR content="MSHTML 8.00.6001.19394">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>
    <body style="font-family:arial,helvetica,sans-serif!important;color:#000;background:#fff;">
    <table>
        <tr>
            <td valign="top">姓名:</td>
            <td valign="top"><?= $_POST["template-contactform-name"?></td>
        </tr>

        <tr>
            <td valign="top">電話:</td>
            <td valign="top"><?= $_POST["template-contactform-phone"?></td>
        </tr>

        <tr>
            <td valign="top">電郵:</td>
            <td valign="top"><?= $_POST["template-contactform-email"?></td>
        </tr>

        <tr>
            <td valign="top">訊息:</td>
            <td valign="top"><?= nl2br($_POST["template-contactform-message"]); ?></td>
        </tr>
    </table>

    <br><br><br><br>

    <?= $site_info{"companyname_" $langcode?><br>
    <a href='<?= $site_info{"url"?>' target='_blank'><?= $site_info{"url"?></a>
    </body>
    </html>

<?php
    $email_body 
ob_get_contents();

    
ob_end_clean();
    
$enquiryemail $site_info{"enquiryemail"};
    
$company_name $site_info{"companyname_" $langcode};

    
//for customer
    
$x_mail = new PHPMailer();
    
$x_mail->CharSet  "UTF-8";
    
$x_mail->Sender   $enquiryemail;
    
$x_mail->AddReplyTo($enquiryemail$company_name);
    
$x_mail->From     $enquiryemail;
    
$x_mail->FromName $company_name;

    
//send to user not send to client
    
$x_mail->AddAddress($enquiryemail$company_name);

    
$x_mail->WordWrap 50;
    
$x_mail->IsHTML(true);
    
$x_mail->Subject $email_subject;
    
$x_mail->Body    $email_body;

    if (
$x_mail->Send()) {
        echo 
"<script>alert('你的查詢已成功送出,我們會儘快回覆。'); window.location.href='contactus.php';</script>";
        exit;
    } else {
        echo 
"<script>alert('你的查詢未能成功送出,請再嘗試。'); history.back();</script>";
        exit;
    }