1<?php
2if (isset($_POST['Email'])) {
3
4 // EDIT THE 2 LINES BELOW AS REQUIRED
5 $email_to = "you@yourdomain.com";
6 $email_subject = "New form submissions";
7
8 function problem($error)
9 {
10 echo "We are very sorry, but there were error(s) found with the form you submitted. ";
11 echo "These errors appear below.<br><br>";
12 echo $error . "<br><br>";
13 echo "Please go back and fix these errors.<br><br>";
14 die();
15 }
16
17 // validation expected data exists
18 if (
19 !isset($_POST['Name']) ||
20 !isset($_POST['Email']) ||
21 !isset($_POST['Message'])
22 ) {
23 problem('We are sorry, but there appears to be a problem with the form you submitted.');
24 }
25
26 $name = $_POST['Name']; // required
27 $email = $_POST['Email']; // required
28 $message = $_POST['Message']; // required
29
30 $error_message = "";
31 $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
32
33 if (!preg_match($email_exp, $email)) {
34 $error_message .= 'The Email address you entered does not appear to be valid.<br>';
35 }
36
37 $string_exp = "/^[A-Za-z .'-]+$/";
38
39 if (!preg_match($string_exp, $name)) {
40 $error_message .= 'The Name you entered does not appear to be valid.<br>';
41 }
42
43 if (strlen($message) < 2) {
44 $error_message .= 'The Message you entered do not appear to be valid.<br>';
45 }
46
47 if (strlen($error_message) > 0) {
48 problem($error_message);
49 }
50
51 $email_message = "Form details below.\n\n";
52
53 function clean_string($string)
54 {
55 $bad = array("content-type", "bcc:", "to:", "cc:", "href");
56 return str_replace($bad, "", $string);
57 }
58
59 $email_message .= "Name: " . clean_string($name) . "\n";
60 $email_message .= "Email: " . clean_string($email) . "\n";
61 $email_message .= "Message: " . clean_string($message) . "\n";
62
63 // create email headers
64 $headers = 'From: ' . $email . "\r\n" .
65 'Reply-To: ' . $email . "\r\n" .
66 'X-Mailer: PHP/' . phpversion();
67 @mail($email_to, $email_subject, $email_message, $headers);
68?>
69
70 <!-- include your success message below -->
71
72 Thank you for contacting us. We will be in touch with you very soon.
73
74<?php
75}
76?>
1if (empty($emailError) && empty($messageError)) {
2 // all the code should go here
3}
4
1<?php
2if ($_SERVER['REQUEST_METHOD'] === 'POST') {
3 // your other code here
4}
5
1<!DOCTYPE html>
2<head>
3 <meta charset="utf-8">
4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5 <title>contact form</title>
6</head>
7
8<body>
9
10<link href="contact-form.css" rel="stylesheet">
11
12<div class="fcf-body">
13
14 <div id="fcf-form">
15 <h3 class="fcf-h3">Contact us</h3>
16
17 <form id="fcf-form-id" class="fcf-form-class" method="post" action="contact-form-process.php">
18
19 <div class="fcf-form-group">
20 <label for="Name" class="fcf-label">Your name</label>
21 <div class="fcf-input-group">
22 <input type="text" id="Name" name="Name" class="fcf-form-control" required>
23 </div>
24 </div>
25
26 <div class="fcf-form-group">
27 <label for="Email" class="fcf-label">Your email address</label>
28 <div class="fcf-input-group">
29 <input type="email" id="Email" name="Email" class="fcf-form-control" required>
30 </div>
31 </div>
32
33 <div class="fcf-form-group">
34 <label for="Message" class="fcf-label">Your message</label>
35 <div class="fcf-input-group">
36 <textarea id="Message" name="Message" class="fcf-form-control" rows="6" maxlength="3000" required></textarea>
37 </div>
38 </div>
39
40 <div class="fcf-form-group">
41 <button type="submit" id="fcf-button" class="fcf-btn fcf-btn-primary fcf-btn-lg fcf-btn-block">Send Message</button>
42 </div>
43
44 <div class="fcf-credit" id="fcf-credit">
45 <a href="https://www.freecontactform.com/form-guides/html-email-form" target="_blank">HTML Email Form</a> from FreeContactForm.com
46 </div>
47
48 </form>
49 </div>
50
51</div>
52
53</body>
54</html>