-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.php
More file actions
49 lines (45 loc) · 1.39 KB
/
validate.php
File metadata and controls
49 lines (45 loc) · 1.39 KB
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
<?php
$msg = "";
$msgClass = "";
if(filter_has_var(INPUT_POST, 'submit'))
{
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);
if(!empty($name) && !empty($email) && !empty($message))
{
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
$toEmail = "jackmaca@msn.com";
$subject = "Contact Request From " . $name;
$body = "<h2>Contact request</h2>
<h4>Name</h4><p>" . $name . "</p>
<h4>Email</h4><p>" . $email . "</p>
<h4>Message</h4><p>" . $message . "</p>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: " . $name . "<" . $email . ">" . "\r\n";
if(mail($toEmail, $subject, $body, $headers))
{
$msg = "Email sent";
$msgClass = "alert-success";
}
else
{
$msg = "Email was not sent";
$msgClass = "alert-danger";
}
}
else
{
$msg = "Enter valid email";
$msgClass = "alert-danger";
}
}
else
{
$msg = "Fill out all inputs";
$msgClass = "alert-danger";
}
}