-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendRefEmail.php
43 lines (32 loc) · 1.15 KB
/
sendRefEmail.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
<?php
$from = $_POST['Name'];
$sendTo = $_POST['Email'];
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'email' => 'Email', 'message' => 'Message'); //
$okMessage = 'Contact form share button submited. Url of page will arrive in few seconds!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
$link = $_SERVER['HTTP_REFERER'];
try
{
$emailText = "$link You got message from shared button.\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
?>