-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_process.php
85 lines (68 loc) · 2.54 KB
/
form_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
if (isset($_POST['email'])) {
// REPLACE THIS 2 LINES AS YOU DESIRE
$email_to = "beaumont.dan@gmail.com";
$email_subject = "Website Form Submission";
function problem($error)
{
echo "Oh looks like there is some problem with your form data: <br><br>";
echo $error . "<br><br>";
echo "Please fix those to proceed.<br><br>";
die();
}
// validation expected data exists
if (
!isset($_POST['firstName']) ||
!isset($_POST['secondName']) ||
!isset($_POST['email']) ||
!isset($_POST['tel']) ||
!isset($_POST['message'])
!isset($_POST['heardAbout'])
) {
problem('Oh no! There looks like there is a problem with your form data.');
}
$firstName = $_POST['firstName']; // required
$secondName = $_POST['LastName']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp, $email)) {
$error_message .= 'Email address does not seem valid.<br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $firstName)) {
$error_message .= 'Name invalid.<br>';
}
if (!preg_match($string_exp, $secondName)) {
$error_message .= 'Name invalid.<br>';
}
if (strlen($message) < 2) {
$error_message .= 'Message should not be less than 2 characters<br>';
}
if (strlen($error_message) > 0) {
problem($error_message);
}
$email_message = "Form details following:\n\n";
function clean_string($string)
{
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
$email_message .= "Name: " . clean_string($firstName + " " + $secondName) . "\n";
$email_message .= "Email: " . clean_string($email) . "\n";
$email_message .= "Tel: " . clean_string($tel) . "\n";
$email_message .= "Subject: " . clean_string($subject) . "\n";
$email_message .= "Message: " . clean_string($message) . "\n";
$email_message .= "How they eard about you: " . clean_string($heardAbout) . "\n";
// create email headers
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- Replace this as your success message -->
Thank you for your message, I'll be in touch as soon as possible.
<?php
}
?>