-
Notifications
You must be signed in to change notification settings - Fork 1
/
mail.php
43 lines (31 loc) · 1.05 KB
/
mail.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
<?php
/*
The Send Mail php Script for Contact Form
Server-side data validation is also added for good data validation.
*/
$data['error'] = false;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if( empty($name) ){
$data['error'] = 'Please enter your name.';
}else if(filter_var($email, FILTER_VALIDATE_EMAIL) == false){
$data['error'] = 'Please enter a valid email address.';
}else if( empty($subject) ){
$data['error'] = 'Please enter your subject.';
}else if( empty($message) ){
$data['error'] = 'The message field is required!';
}else{
$formcontent="From: $name\nSubject: $subject\nEmail: $email\nMessage: $message";
//Place your Email Here
$recipient = "your_mail@your_domain.com";
$mailheader = "From: $email \r\n";
if( mail($recipient, $name, $formcontent, $mailheader) == false ){
$data['error'] = 'Sorry, an error occured!';
}else{
$data['error'] = false;
}
}
echo json_encode($data);
?>