Skip to content

Instantly share code, notes, and snippets.

@Murazaki
Last active October 14, 2016 14:31
Show Gist options
  • Save Murazaki/616f845f65ee203fa9f6aae98f8ea525 to your computer and use it in GitHub Desktop.
Save Murazaki/616f845f65ee203fa9f6aae98f8ea525 to your computer and use it in GitHub Desktop.
Simple Send Mail PHP from POST variables
<?php
$to = isset($_POST["to"])? $_POST["to"] : ''; // 'personne@example.com';
$subject = isset($_POST["subject"])? $_POST["subject"] : ''; // 'le sujet';
$message = isset($_POST["message"])? $_POST["message"] : ''; // 'Bonjour !';
$headers = 'From: '.( isset($_POST["from"])? $_POST["from"] : '') .'\r\n' . // 'From: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
echo mail($to, $subject, $message, $headers);
?>
<?php
$_POST = json_decode(file_get_contents('php://input'), true);
$to = isset($_POST["to"])? $_POST["to"] : ''; // 'personne@example.com';
$subject = isset($_POST["subject"])? $_POST["subject"] : ''; // 'le sujet';
$message = isset($_POST["message"])? $_POST["message"] : ''; // 'Bonjour !';
$headers = 'From: '.( isset($_POST["from"])? $_POST["from"] : '') .'\r\n' . // 'From: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
echo mail($to, $subject, $message, $headers);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment