-
Notifications
You must be signed in to change notification settings - Fork 1
/
submitemail.php_disabled
53 lines (35 loc) · 966 Bytes
/
submitemail.php_disabled
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
<?php
$to = "myemail@domain.com"; // Replace with your email address
$subject = "Message from ".ucwords($_POST['name']); // Enter the subject here.
//Validating email addres
$email = $_POST['email'];
function validateEmail($email)
{
if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$', $email))
return true;
else
return false;
}
//Validates the required fields
if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){
$emailerror .= true;
} else {
$emailerror .= false;
//Composing the email
$email_message =
"Name: " . ucwords($_POST['name']) . "\n" .
"Email: " . $email . "\n" .
"Message: " . "\n" . $_POST['message'] . "\n";
//Sending the email
mail($to, $subject, $email_message);
}
?>
<?php
if($emailerror == true) {
echo '<span>Please fill all the fields.</span>';
}
else
{
echo "<span>Message has been sent. Thank you!</span>";
}
?>