forked from samdoiron/wds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.php
35 lines (27 loc) · 770 Bytes
/
email.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
<?php
// TODO:
// Match provided token with stored token
// Send email to ourselves with provided information
$to = '[email protected]';
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['from'];
$headers = 'From: ' . $from . "\r\n" .
'Reply-To: ' . $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$errors = 0;
header('Content-type: application/json');
if (! preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $from) ) {
echo '{"error":"Email Address is Invalid."}';
exit();
}
if (empty($subject)) {
echo '{"error":"Subject cannot be empty."}';
exit();
}
if (empty($message)) {
echo '{"error":"Message cannot be empty."}';
exit();
}
mail($to, $subject, $message, $headers);
echo '{"success":"Email has been sent."}';