-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontactnew.php
96 lines (65 loc) · 2.76 KB
/
contactnew.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
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = '[email protected]';
$email_template = 'contactnew.html';
$name = strip_tags($_GET['name']);
$email = strip_tags($_GET['email']);
$country = strip_tags($_GET['country']);
$phone = strip_tags($_GET['phone']);
$subject = 'Subscribe';
$message = nl2br( htmlspecialchars($_GET['message'], ENT_QUOTES) );
$result = array();
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> Name is empty.' );
echo json_encode($result );
die;
}
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> Email is empty.' );
echo json_encode($result );
die;
}
if(empty($phone)){
$result = array( 'response' => 'error', 'empty'=>'phone', 'message'=>'<strong>Error!</strong> Mobile no. is empty.' );
echo json_encode($result );
die;
}
if(empty($country)){
$result = array( 'response' => 'error', 'empty'=>'country', 'message'=>'<strong>Error!</strong> Country is empty.' );
echo json_encode($result );
die;
}
// if(empty($subject)){
// $result = array( 'response' => 'error', 'empty'=>'subject', 'message'=>'<strong>Error!</strong> Subject is empty.' );
// echo json_encode($result );
// die;
// }
if(empty($message)){
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Message body is empty.' );
echo json_encode($result );
die;
}
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}'=>$email,
'{{message}}'=>$message,
'{{country}}'=>$country,
'{{name}}'=>$name,
'{{phone}}'=>$phone
);
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Thank You!</strong> Your email has been delivered.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Cann\'t Send Mail.' );
}
echo json_encode( $result );
die;
?>