-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.php
81 lines (70 loc) · 2.38 KB
/
send_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
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
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the phone field is not empty
if(trim($_POST['phone']) == '') {
$hasError = true;
} else {
$phone = trim($_POST['phone']);
}
//Check to make sure that the delivery field is not empty
if(trim($_POST['delivery']) == '') {
$hasError = true;
} else {
$delivery = trim($_POST['delivery']);
}
//Check to make sure that the physical address field is not empty
if(trim($_POST['address']) == '') {
$hasError = true;
} else {
$address = trim($_POST['address']);
}
//Check to make sure that the restaurant field is not empty
if(trim($_POST['restaurant']) == '') {
$hasError = true;
} else {
$restaurant = trim($_POST['restaurant']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '[email protected]'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nPhone Number: $phone \n\nPhysical address: $address \n\nDesired Delivery Time: $delivery \n\nRestaurant: $restaurant \n\nOrder Info:\n $comments";
$headers = 'From: Palo Alto Delivery <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$subject = "Order Request";
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
if (isset($hasError)) {
echo "<p>Please check if you've filled all the fields with valid information and try again. Thank you.</p>" .
"<a href='/'>Go Back</a>";
}
if(isset($emailSent) && $emailSent == true) {
echo "<p><strong>Order Successfully Sent!</strong></p>" .
"<p>Thank you for using Palo Alto Delivery. Your order was successfully sent and we’ll call you back to confirm your order as soon as possible.</p>";
}
}
?>