-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmail.php
37 lines (29 loc) · 1.05 KB
/
sendmail.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
<?php
// Variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['sub']);
$message = trim($_POST['message']);
if( isset($name) && isset($email) && isset($message) && is_email_valid($email) ) {
// Avoid Email Injection and Mail Form Script Hijacking
$pattern = "/(content-type|bcc:|cc:|to:)/i";
if( preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $message) ) {
exit;
}
// Email will be send
$to = "[email protected]"; // Change with your email address
$sub = "$name - $subject"; // You can define email subject
// HTML Elements for Email Body
$body = <<<EOD
<strong>Name:</strong> $name <br>
<strong>Email:</strong> <a href="mailto:$email?subject=feedback" "email me">$email</a> <br> <br>
<strong>Message:</strong> $message <br>
EOD;
//Must end on first column
$headers = "From: $name <$email>\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// PHP email sender
mail($to, $sub, $body, $headers);
}
?>