mailer.php 729 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. if($_SERVER['REQUEST_METHOD'] != 'POST') {
  3. include error(403);
  4. die;
  5. }
  6. if($_POST['captcha'] != '') {
  7. include error(403);
  8. die;
  9. }
  10. $senderName = trim(filter_var($_POST['name'], FILTER_SANITIZE_STRING));
  11. $senderEmail = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  12. $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
  13. $headers = '';
  14. $headers .= "Content-Type: text/plain; charset=utf-8\r\n";
  15. $headers .= "From: $senderName <$senderEmail>\r\n";
  16. $result = mail("andrea.franceschini@gmail.com", "Website contact", $message, $headers);
  17. if($result == 1) {
  18. $ref = filter_var($_SERVER['HTTP_REFERER'], FILTER_SANITIZE_URL);
  19. session_start();
  20. $_SESSION['contact_thanks'] = 1;
  21. header("Location: $ref");
  22. }