-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact-form.php
85 lines (62 loc) · 1.75 KB
/
contact-form.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
$connect = mysqli_connect('<DB_HOST>', '<DB_USERNAME>', '<DB_PASSWORD>', '<DB_DATABASE>');
$email = isset( $_POST['email'] ) ? $_POST['email'] : '';
$message = isset( $_POST['message'] ) ? $_POST['message'] : '';
$email_error = '';
$message_error = '';
if (count($_POST))
{
$errors = 0;
if ($_POST['email'] == '')
{
$email_error = 'Please enter an email address';
$errors ++;
}
if ($_POST['message'] == '')
{
$message_error = 'Please enter a message';
$errors ++;
}
if ($errors == 0)
{
$query = 'INSERT INTO contact (
email,
message
) VALUES (
"'.addslashes($_POST['email']).'",
"'.addslashes($_POST['message']).'"
)';
mysqli_query($connect, $query);
$message = 'You have received a contact form submission:
Email: '.$_POST['email'].'
Message: '.$_POST['email'];
mail( '[email protected]',
'Contact Form Cubmission',
$message );
header('Location: thankyou.html');
die();
}
}
?>
<!doctype html>
<html>
<head>
<title>PHP Contact Form</title>
</head>
<body>
<h1>PHP Contact Form</h1>
<form method="post" action="">
Email Address:
<br>
<input type="text" name="email" value="<?php echo $email; ?>">
<?php echo $email_error; ?>
<br><br>
Message:
<br>
<textarea name="message"><?php echo $message; ?></textarea>
<?php echo $message_error; ?>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>