-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave_contact_msg.php
executable file
·48 lines (38 loc) · 1.34 KB
/
save_contact_msg.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
<?php
require("db.php");
$link = mysqli_connect($_srvr, $_user, $_pass, $_db);
function sanitize ($data) {
global $link;
$data = trim($data);
$data = mysqli_real_escape_string($link, $data);
return $data;
}
$email = sanitize($_POST['email']);
$name = sanitize($_POST['name']);
$msg = sanitize($_POST['msg']);
function regularemail ($email) {
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $email))
return true;
else
return false;
}
if (regularemail($email)) {
$query = "INSERT INTO `contact_us`(`email`, `name`, `message`) VALUES (?,?,?)";
$email = sanitize($email);
$statement = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($statement,'sss', $email, $name, $msg);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement); // close the prepared statement
$to = "shubh_jain94@yahoo.in,kartikbansal945@gmail.com";
$subject = "Orenda Contact Message";
$message = "From: $email\r\nName: $name\r\nMessage: $msg\r\n\r\nRegards,\r\nRaghav Garg\r\nBack End Developer";
$headers = 'From: help@techorenda.com' . "\r\n" .
'Reply-To: help@techorenda.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "saved";
} else {
echo "not_valid";
}
mysqli_close($link); // close the sql connection
?>