-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
70 lines (62 loc) · 1.92 KB
/
process.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
<?php
if(isset($_POST) ){
$this_form_spam = $_POST['firstname'];
/* if firstname field is not empty then prevent form submission.
firstname field is likely to be completed by automated spambots.
Humans won't complete this field as it's hidden. */
if ($this_form_spam == "") {
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//get form data
$name = $_POST['name'];
$email = $_POST['email'];
//validate form data
if(empty($name)){
$formok = false;
$errors[] = "Please enter your name";
}
if(empty($email)){
$formok = false;
$errors[] = "Please enter your email";
} elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$formok = false;
$errors[] = "Please enter a valid email address";
}
//send email if all is ok
if($formok){
$headers = "From: [email protected]" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$emailbody = "<p><strong>Name: </strong> {$name} </p>
<p><strong>Email: </strong> {$email} </p>
<hr>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
mail("[email protected]","AJAX Abide form response",$emailbody,$headers);
}
//what we need to return back to our form
$returndata = array(
'posted_form_data' => array(
'name' => $name,
'email' => $email
),
'form_ok' => $formok,
'errors' => $errors
);
//if this is not an ajax request
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
//set session variables
session_start();
$_SESSION['cf_returndata'] = $returndata;
//redirect back to form
header('location: ' . $_SERVER['HTTP_REFERER']);
}
}
else {
//just send the spammers back, seeya
header('location: ' . $_SERVER['HTTP_REFERER']);
}
}