-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
44 lines (33 loc) · 1.04 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
<?php
if ($_POST) {
$toEmail = '[email protected]';
$values = [];
if ($_POST['name']) {
$subject = 'Contact Request From ' . htmlspecialchars($_POST['name']);
} else {
$subject = 'Contact Request';
}
foreach ($_POST as $propName => $propValue) {
if ($propName !== 'message') {
$values[] = 'Visitor ' . htmlspecialchars($propName) . ': ' . htmlspecialchars($propValue);
}
}
if ($_POST['message']) {
$values[] = '<br>Visitor message:<br><br>' . htmlspecialchars($_POST['message']);
}
$body = implode('<br>', $values);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type:text/html;charset=UTF-8" . "\r\n";
if ($_POST['name'] || $_POST['email']) {
$headers .= "From: ";
}
if ($_POST['name']) {
$headers .= htmlspecialchars($_POST['name']);
}
if ($_POST['email']) {
$headers .= "<" .htmlspecialchars($_POST['email']). ">";
}
$headers .= "\r\n";
mail($toEmail, $subject, $body, $headers);
}
?>