1<?php
2if(!empty($_POST["send"])) {
3 $name = $_POST["userName"];
4 $email = $_POST["userEmail"];
5 $subject = $_POST["subject"];
6 $content = $_POST["content"];
7
8 $toEmail = "admin@phppot_samples.com";
9 $mailHeaders = "From: " . $name . "<". $email .">\r\n";
10 if(mail($toEmail, $subject, $content, $mailHeaders)) {
11 $message = "Your contact information is received successfully.";
12 $type = "success";
13 }
14}
15require_once "contact-view.php";
16?>
1<html>
2<head>
3 <title>PHP Contact Form - The Email Method - Hyvor Developer</title>
4</head>
5<body>
6
7<form method="POST" action="">
8 <div class="input-wrap">
9 <span class="label">Email:</span>
10 <input type="text" name="email">
11 </div>
12 <div class="input-wrap">
13 <span class="label">Message:</span>
14 <textarea name="message"></textarea>
15 </div>
16 <div class="input-wrap">
17 <input type="submit" name="submit" value="Submit" class="submit-button">
18 </div>
19
20</form>
21
22</body>
23</html>
24
1<html>
2<head>
3<title>PHP Contact Form</title>
4<link rel="stylesheet" type="text/css" href="style.css" />
5</head>
6<body>
7 <div class="form-container">
8 <form name="frmContact" id="" frmContact"" method="post"
9 action="" enctype="multipart/form-data"
10 onsubmit="return validateContactForm()">
11
12 <div class="input-row">
13 <label style="padding-top: 20px;">Name</label> <span
14 id="userName-info" class="info"></span><br /> <input
15 type="text" class="input-field" name="userName"
16 id="userName" />
17 </div>
18 <div class="input-row">
19 <label>Email</label> <span id="userEmail-info"
20 class="info"></span><br /> <input type="text"
21 class="input-field" name="userEmail" id="userEmail" />
22 </div>
23 <div class="input-row">
24 <label>Subject</label> <span id="subject-info"
25 class="info"></span><br /> <input type="text"
26 class="input-field" name="subject" id="subject" />
27 </div>
28 <div class="input-row">
29 <label>Message</label> <span id="userMessage-info"
30 class="info"></span><br />
31 <textarea name="content" id="content"
32 class="input-field" cols="60" rows="6"></textarea>
33 </div>
34 <div>
35 <input type="submit" name="send" class="btn-submit"
36 value="Send" />
37
38 <div id="statusMessage">
39 <?php
40 if (! empty($message)) {
41 ?>
42 <p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
43 <?php
44 }
45 ?>
46 </div>
47 </div>
48 </form>
49 </div>
50
51 <script src="https://code.jquery.com/jquery-2.1.1.min.js"
52 type="text/javascript"></script>
53 <script type="text/javascript">
54 function validateContactForm() {
55 var valid = true;
56
57 $(".info").html("");
58 $(".input-field").css('border', '#e0dfdf 1px solid');
59 var userName = $("#userName").val();
60 var userEmail = $("#userEmail").val();
61 var subject = $("#subject").val();
62 var content = $("#content").val();
63
64 if (userName == "") {
65 $("#userName-info").html("Required.");
66 $("#userName").css('border', '#e66262 1px solid');
67 valid = false;
68 }
69 if (userEmail == "") {
70 $("#userEmail-info").html("Required.");
71 $("#userEmail").css('border', '#e66262 1px solid');
72 valid = false;
73 }
74 if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/))
75 {
76 $("#userEmail-info").html("Invalid Email Address.");
77 $("#userEmail").css('border', '#e66262 1px solid');
78 valid = false;
79 }
80
81 if (subject == "") {
82 $("#subject-info").html("Required.");
83 $("#subject").css('border', '#e66262 1px solid');
84 valid = false;
85 }
86 if (content == "") {
87 $("#userMessage-info").html("Required.");
88 $("#content").css('border', '#e66262 1px solid');
89 valid = false;
90 }
91 return valid;
92 }
93</script>
94</body>
95</html>
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>