-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailer.php
More file actions
87 lines (63 loc) · 3.27 KB
/
mailer.php
File metadata and controls
87 lines (63 loc) · 3.27 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
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["form__name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["form__email"]), FILTER_SANITIZE_EMAIL);
$tel = strip_tags(trim($_POST["form__tel"]));
$tel = str_replace(array("\r","\n"),array(" "," "),$tel);
$message = trim($_POST["form__message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($email) ) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! Name and email are required!";
exit;
}
if ( !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! Email is invalid.";
exit;
}
// Set the recipient email address.
$recipient = "cff@eiendomsmegler1.no";
//$recipient = "szabogabi@gmail.com";
// Set the email subject.
$subject = 'Pengeskapsfabrikken contact from '.$name;
$subject2 = 'Takk for din henvendelse.';
$email_content2='Du er nå registrert som interessent i boligprosjektet Pengeskapsfabrikken.'."\r\n".'Vi jobber nå med utarbeidelse av hjemmeside og prospekt.'."\r\n".'Som registrert interessent holder vi deg fortløpende orientert om fremdriften.';
// Build the email content.
$email_content = 'Name: '.$name."\r\n";
$email_content .= 'Email: '.$email."\r\n";
$email_content .= 'Tel: '.$tel."\r\n";
$email_content .= 'Message:'."\r\n".$message."\r\n";
// Build the email headers.
$htmlheaders = 'MIME-Version: 1.0' . "\r\n";
$htmlheaders .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$email_headers = $htmlheaders. 'From: '.$name.' <'.$email.'>'. "\r\n";
$email_headers2 = $htmlheaders. 'From: Christian Fr. Foss <'.$recipient.'>'. "\r\n";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Takk for din henvendelse.";
echo '<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6037119513304&cd[value]=0.01&cd[currency]=USD&noscript=1" /></noscript>';
$txt = "../../uploads/emails/data.txt";
$fh = fopen($txt, 'a');
$txt=date("F j, Y, g:i a").' | '.$name.' | '.$email.' | '.$tel.' | '.str_replace(array("\r","\n"),array(" "," "),$message).PHP_EOL;
fwrite($fh,$txt);
fclose($fh);
//confirmation email
mail($email, $subject2, $email_content2, $email_headers2);
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
?>