code-dumps/php/mailapi.php

26 lines
780 B
PHP
Raw Normal View History

2021-04-30 11:51:41 +08:00
<?php
if (empty($_POST)) {
echo 'Usage: curl -d "subject=email subject&sender=SENDER@DOMAIN.TLD&recipient=RECIPIENT@DOMAIN.TLD&message=$(base64 /tmp/mailbody.txt)" -X POST https://racker.pro/mailapi/';
exit();
} else {
$to = $_POST['recipient'];
$subject = $_POST['subject'];
2022-09-07 10:31:34 +08:00
$headers = "From: " . $_POST['sender'] . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = str_replace(" ", "&nbsp;", base64_decode($_POST['message']));
$message2 = "<span style=\"font-family: monospace; font-size: small;\">" . str_replace("\n", "<br />\n", $message) . "</span>";
2021-04-30 11:51:41 +08:00
2022-09-07 10:31:34 +08:00
if (mail($to, $subject, $message2, $headers)) {
2021-04-30 11:51:41 +08:00
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}
2022-09-07 10:31:34 +08:00
}
2021-04-30 11:51:41 +08:00
?>