forked from melqueemerson/fundelphus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
112 lines (98 loc) · 2.71 KB
/
contact.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
<?php
// EDIT THE FOLLOWING LINE BELOW AS REQUIRED
$send_email_to = "melque_tcd@hotmail.com";
function send_email($name,$email,$phone,$subject,$message)
{
global $send_email_to;
if($message=='message')$message='';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$message = "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Name = </strong>".$name."<br>";
$message .= "<strong>Phone = </strong>".$phone."<br>";
$message .= "<strong>Message = </strong>".$message."<br>";
@mail($send_email_to, $subject, $message,$headers);
return true;
}
function validate($name,$email,$phone,$message,$subject)
{
$return_array = array();
$return_array['success'] = '1';
$return_array['name_msg'] = '';
$return_array['email_msg'] = '';
$return_array['phone_msg'] = '';
$return_array['message_msg'] = '';
$return_array['subject_msg'] = '';
if($email == '')
{
$return_array['success'] = '0';
$return_array['email_msg'] = 'email is required';
}
else
{
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$return_array['success'] = '0';
$return_array['email_msg'] = 'Enter valid email.';
}
}
if($name == '')
{
$return_array['success'] = '0';
$return_array['name_msg'] = 'Name is required';
}
else
{
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$return_array['success'] = '0';
$return_array['name_msg'] = 'Enter valid Name.';
}
}
if($phone == '')
{
$return_array['success'] = '0';
$return_array['phone_msg'] = 'Phone is required';
}
else
{
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $phone)) {
$return_array['success'] = '0';
$return_array['phone_msg'] = 'Enter valid Phone.';
}
}
if($subject == '')
{
$return_array['success'] = '0';
$return_array['subject_msg'] = 'Subject is required';
}
if($message == '')
{
$return_array['success'] = '0';
$return_array['message_msg'] = 'Message is required';
}
else
{
if (strlen($message) < 2) {
$return_array['success'] = '0';
$return_array['message_msg'] = 'Enter valid Message.';
}
}
return $return_array;
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$return_array = validate($name,$email,$phone,$message,$subject);
if($return_array['success'] == '1')
{
send_email($fname,$email,$phone,$subject,$message);
}
header('Content-type: text/json');
echo json_encode($return_array);
die();
?>