-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
97 lines (89 loc) · 2.97 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
<?php
// check if form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
// validate form fields
if($name == '' OR $email == '' OR $message == ''){
$error_message = "You must specify a value for name, email and message.";
}
// address field is hidden to prevent bots' spamming, 'normal' customers won't see this field
if($_POST["address"] != ''){
$error_message = "Your form submission has a problem.";
}
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$to = "hnv1002@rit.edu";
$subject = "New Message from my website";
$header = "From: ".$name."\n";
if(!isset($error_message)){
// send customer form submission to my email
mail($to,$subject,$email_body,$header);
// redirect customer to a reponse page after submission
header("Location: contact.php?status=thanks");
exit;
}
}
$pageTitle = "Contact Huy";
$section = "contact";
include("inc/header.php");
?>
<div class="section page">
<div class="wrapper">
<h1>Contact</h1>
<?php if(isset($_GET["status"]) && $_GET["status"] == "thanks"){?>
<p>Thanks for the email. I’ll be in touch shortly!</p>
<?php }else{ ?>
<?php if(!isset($error_message)){
echo "<p>I’d love to hear from you! Complete the form to send me an email.</p>";
}else{
echo '<p class="message">'.$error_message."</p>";
}
?>
<form method="post" action="contact.php">
<!-- Contact form -->
<table>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<tr>
<th>
<label for="email">Email</label>
</th>
<td>
<input type="text" name="email" id="email">
</td>
</tr>
<tr>
<th>
<label for="message">Message</label>
</th>
<td>
<textarea name="message" id="message"></textarea>
</td>
</tr>
<!-- hidden field to prevent bots-->
<tr style="display: none;">
<th>
<label for="address">Address</label>
</th>
<td>
<input type="text" name="address" id="address">
<p>Please leave this field blank.</p>
</td>
</tr>
</table>
<input type="submit" value="Send">
</form>
<?php } ?>
</div>
</div>
<?php include("inc/footer.php"); ?>