forked from StarkIndi/starkindi.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.php
executable file
·36 lines (28 loc) · 1.24 KB
/
subscribe.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
<?php
if($_POST)
{
$to_email = "[email protected]"; //Recipient email, Replace with own email here
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
$output = json_encode(array( //create JSON data
'type'=>'error',
'text' => 'Sorry Request must be Ajax POST'
));
die($output); //exit script outputting json data
}
$name = 'Ticker';
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//Sanitize input data using PHP filter_var().
$email = filter_var($_POST["subscribe_email"], FILTER_SANITIZE_EMAIL);
$output = json_encode(array('type'=>'message', 'text' => 'Thank you. Your email was sent successfully.'));
$send_mail = @mail($to_email, '', 'You have a new subscriber '.$email , $headers);
die($output);
if(!$send_mail) {
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}
}
?>