forked from greensteph/greensteph.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_form_email.php
55 lines (44 loc) · 1.7 KB
/
send_form_email.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
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]"; //YOUR EMAIL
$email_subject = "New Portfolio Contact"; //YOUR SUBJECT
function died($error) {
echo $error."<br /><br />";
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name'];
$email_from = $_POST['email'];
$comments = $_POST['message'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= '<div class="email-erorr">Please enter a valid email.</div>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= '<div class="name-erorr">Please enter your name.</div>';
}
if(strlen($comments) < 2) {
$error_message .= '<div class="message-erorr">Please enter a message.</div>';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n";
mail($email_to, $email_subject, $email_message, $headers);
?>
<div class="success_message">Your message was sent.</div>
<?php } ?>