-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.php
89 lines (71 loc) · 2.99 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
82
83
84
85
86
87
88
89
<?php
include 'config.php';
$captcha;
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
}
if (!$captcha) {
$error_msg = "reCaptcha challenge failed. Please check the reCaptcha again and verify you are not a robot.";
echo "<script type='text/javascript'>alert('$error_msg');</script>";
header("Refresh: 3; url=index.html");
exit();
} else {
if(isset($_POST['email'])) {
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['contact']) ||
!isset($_POST['product']) ||
!isset($_POST['message'])
) {
died('Sorry, there appears to be a problem with your form submission. Please try again.');
header('Refresh: 5;');
}
$full_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['contact']; // not required
$product = $_POST['product']; // not required
$comments = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$email_from)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($full_name) < 2) {
$error_message .= 'Your Name does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "A new enquiry has been sent from $full_name. <$email_from>\r\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($full_name)."\r\n";
$email_message .= "Email: ".clean_string($email_from)."\r\n";
$email_message .= "Contact Number: ".clean_string($telephone)."\r\n";
$email_message .= "Product/Service: ".clean_string($product)."\r\n\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$email_subject = "machine-rebuilding.com - New enquiry from $full_name <$email_from>";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
}
die();
?>