-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproses.php
More file actions
62 lines (50 loc) · 1.61 KB
/
proses.php
File metadata and controls
62 lines (50 loc) · 1.61 KB
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
<?php
if (isset($_POST)) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$errors = array();
$formok = true;
if ($name === "") {
$formok = false;
$errors['name'] = "You have not fill your name";
}
if ($email === "") {
$formok = false;
$errors['email'] = "You have not fill your email";
} elseif ( ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
$formok = false;
$errors['email'] = "Your email is not valid";
}
if ($message === "") {
$formok = false;
$errors['message'] = "You have not fill the message";
}
if ($formok) {
$headers = "From: bot@comprofile.com" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$emailbody = "you got a message from " . $name . " (" . $email . ")";
$emailbody .= "message: " . $message;
mail("bahrunnur20@gmail.com", "Pesan dari Comprofile", $emailbody, $headers);
}
$formvalue = array(
'name' => $name,
'email' => $email,
'message' => $message
);
$returndata = array(
'errors' => $errors,
'status' => $formok,
'formvalue' => $formvalue
);
if (empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') {
// ngeset variabel session
session_start();
$_SESSION['returned'] = $returndata;
// kembali ke halaman contact
header('location: ' . $_SERVER['HTTP_REFERER']);
}
} else {
header('location: index.php');
}