-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquestionform.php
More file actions
74 lines (58 loc) · 2.59 KB
/
questionform.php
File metadata and controls
74 lines (58 loc) · 2.59 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
63
64
65
66
67
68
69
70
71
72
73
74
<?php
function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}
error_reporting(E_ALL);
if(isset($_POST['submit'])) {
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Get user IP address
if ( isset($_SERVER['HTTP_CLIENT_IP']) && ! empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
}
$ip = filter_var($ip, FILTER_VALIDATE_IP);
$ip = ($ip === false) ? '0.0.0.0' : $ip;
$date = new DateTime('now', new DateTimeZone('GMT'));
$email_to="CoderDojoD15@gmail.com";
$email_subject="Question from CoderDojo Website";
$name = $_POST['questionform_name'];
$email_from = $_POST['questionform_email'];
$message = $_POST['questionform_message'];
// create email headers
$headers = "From: " . $name." <".$email_from . "\r\n";
$headers .= "Reply-To: ". $name." <".$email_from . "\r\n";
// $headers .= "CC: rdas@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$email_message ="<html><body>";
$email_message .= "<p> A question from : ".$name." (".$email_from.").</br></p>";
$email_message .= "<p> on : ".$date->format('d/M/Y H:i')."\r\n</p>";
$email_message .= "<p> <b>".$message."</b></br>\r\n</p>";
$email_message .= "<p> from ip : ".$ip."\r\n</p>";
$email_message .= "</body></html>";
// echo("name: " . $name . "<br />\n");
// echo("email: " . $email_from . "<br />\n");
// echo("message: " . $email_message . "<br />\n");
// echo("sent: " . $sent . "<br />\n");
$sent = @mail($email_to, $email_subject, $email_message, $headers);
if ($sent) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
} else {
echo("We encountered an error sending your mail");
}
}
?>