Skip to content

Instantly share code, notes, and snippets.

@Mr-Ventures
Last active April 28, 2021 07:17
Show Gist options
  • Save Mr-Ventures/5732a45e29205f2d88680011fd3de7de to your computer and use it in GitHub Desktop.
Save Mr-Ventures/5732a45e29205f2d88680011fd3de7de to your computer and use it in GitHub Desktop.
// Emailer.php
// http://www.mrventures.net/all-tutorials/sending-emails
<?php
// This code lives on my server at https://files.000webhost.com/
// This allows us to send data back to Unity
header("Access-Control-Allow-Origin: *");
// Evaluate data are all present
if (isset($_REQUEST["name"]) && isset($_REQUEST["fromEmail"])
&& isset($_REQUEST["toEmail"]) && isset($_REQUEST["message"]))
{
echo "Trying to send...";
}
else
{
echo "Bad data, exiting...";
exit("");
}
//Define the $_POST variables...
$name = $_REQUEST['name'];
$toEmail = $_REQUEST['toEmail'];
$message = $_REQUEST['message'];
$fromEmail = $_REQUEST['fromEmail'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: " . $fromEmail . "\r\n" .
"Reply-To: " . $fromEmail . "\r\n" .
"X-Mailer: PHP/" . phpversion();
//Send the email and print sender confirmation...
$success = mail( $toEmail, "Fancy Title", $message, $headers);
if ($success)
{
echo('Your message has been sent successfully!');
}
else
{
echo(error_get_last()['message']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment