Last active
January 20, 2021 17:20
-
-
Save hellwolf/08afdd7d1949524d01ac073847976857 to your computer and use it in GitHub Desktop.
mail.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $SECRET = '....'; | |
| header("Content-type: application/json"); | |
| if ($_GET["secret"] != $SECRET) { | |
| http_response_code(401); | |
| echo json_encode(array( | |
| "success" => false, | |
| "status_code" => 401 | |
| )); | |
| return; | |
| } | |
| $postData=file_get_contents("php://input"); | |
| $additional_options = ""; | |
| $headers = ""; | |
| $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n"; | |
| $headers .= 'MIME-Version: 1.0' . "\r\n";/* note double quote here*/ | |
| $headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";/* here too*/ | |
| if (isset($_GET["from"])) { | |
| $headers .= "From: <".$_GET["from"].">\r\n"; | |
| $headers .= "Return-Path: <".$_GET["from"].">\r\n"; | |
| $additional_options = " -f ". $_GET["from"]; | |
| } | |
| if (isset($_GET["replyto"])) { | |
| $headers .= "Reply-To: <".$_GET["replyto"].">\r\n"; | |
| } | |
| $to = isset($_GET["to"]) ? $_GET["to"] : "root"; | |
| $subject = isset($_GET["subject"]) ? $_GET["subject"] : "Mail sent by mail.php"; | |
| $REQUEST = $_REQUEST; | |
| unset($REQUEST["secret"]); | |
| $message .= json_encode(json_decode($postData), JSON_PRETTY_PRINT); | |
| http_response_code(202); | |
| mail($to, $subject, $message, $headers, $additional_options); | |
| echo json_encode(array( | |
| "success" => true, | |
| "status_code" => 202 | |
| )); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment