-
Notifications
You must be signed in to change notification settings - Fork 0
/
getEmailAddy.php
executable file
·48 lines (40 loc) · 1.67 KB
/
getEmailAddy.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
44
45
46
47
48
<?php
// define variables and set to empty values
$email = "";
function cleanInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = filter_var(cleanInput($_POST["emailaddy"]), FILTER_SANITIZE_EMAIL);
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Whoops! There appears to be an issue with your email address. Please try again.";
exit;
}
// Set the from email address.
$from = "[email protected]";
// Set the recipient email address.
$recipient = "[email protected]";
// Set the email subject.
$subject = "$email Subscribed!";
// Build the email content.
$email_content = "Hi WillSenge! You've received a new subscription. Here's the email address below:\n\n";
$email_content .= "Email: $email\n\n";
// Build the email headers.
$email_headers = "From: <$from>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "<h5><strong>Success!</strong> You've been subscribed. Look out for an introduction email soon.</h5>";
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "<strong>Whoops!</strong> This is embarrasing. Something went wrong on my end.";
}
}
?>