code-dumps/php/mailapi.php

26 lines
780 B
PHP

<?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'];
$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>";
if (mail($to, $subject, $message2, $headers)) {
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}
}
?>