-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
82 lines (74 loc) · 2.21 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
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
<!--<?php
session_start();
$con=mysqli_connect('localhost','root','');
mysqli_select_db($con,'hms');
if(isset($_POST['submit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$number = $_POST['number'];
$msg = $_POST['message'];
$reg="insert into contactus(firstname,lastname,email,phoneno,message) values ('$firstname','$lastname','$email','$number','$msg')";
mysqli_query($con,$reg);
$to = "ganapathy5subramanian@gmail";
$subject = "HTML email";
$message="Name:".$firstname.$lastname."\n"."PhoneNumber :".$number."\n"."Message:".$msg;
$headers="From:".$email;
if(mail($to,$subject,$message,$headers)){
echo '<script>alert("message send successfull" " " .$firstname."we will contact you shortly!!")</script>';
}
else
{
echo "<script>alert('someting wrong')</script>";
}
}
?>-->
<?php
if(isset( $_POST['firstname']))
$firstname = $_POST['firstname'];
if(isset( $_POST['lastname']))
$lastname = $_POST['lastname'];
if(isset( $_POST['email']))
$email = $_POST['email'];
if(isset( $_POST['number']))
$number = $_POST['number'];
if(isset( $_POST['sub']))
$subject = $_POST['sub'];
if(isset( $_POST['message']))
$message = $_POST['message'];
if ($firstname ===''){
echo "<script>window.alert('FirstName cannot be empty.')</script>";
die();
}
if ($lastname ===''){
echo "<script>window.alert(LastName cannot be empty.')</script>";
die();
}
if ($email === ''){
echo "<script>window.alert(Email cannot be empty.')</script>";
die();
} else {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "<script>window.alert(Email format invalid.')</script>";
die();
}
}
if ($number === ''){
echo "<script>window.alert(Mobile number cannot be empty.')</script>";
die();
}
if ($subject === ''){
echo "Subject cannot be empty.";
die();
}
if ($message === ''){
echo "<script>window.alert(Message cannot be empty.')</script>";
die();
}
$content="From: $firstname $lastname\nPhone Number: $number \nEmail: $email \nMessage: $message";
$recipient = "[email protected]";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $content, $mailheader) or die("Error!");
echo "Email sent!";
?>