PHP   10

perfect-v2.2.2.php

Guest on 10th August 2021 04:48:43 PM

  1. <?php
  2. ///////////////////////////////////////////////////////
  3. // PERFECT PHP                                       //
  4. // v2.2.2 (April 19, 2021)                           //
  5. // Process a web form to extract the user input and  //
  6. //    then email the data to a predefined recipient. //
  7. // MIT License or WTFPL (your choice)                //
  8. // https://centerkey.com/php                         //
  9. ///////////////////////////////////////////////////////
  10.  
  11. // Configuration settings
  12. $sendFrom =    "Feedback <feedback@yourdomain.com>";
  13. $sendTo =      "username@yourdomain.com";
  14. $subjectLine = "Feedback Submission";
  15. $thanksUrl =   "thanks.html";  //confirmation page
  16.  
  17. // Build message body from web form input
  18. $lines = array($_SERVER["SERVER_NAME"], '');
  19. foreach ($_POST as $field=>$value)
  20.    array_push($lines, "$field: $value");
  21. array_push($lines, '', @gethostbyaddr($_SERVER["REMOTE_ADDR"]), '');
  22. $body = htmlspecialchars(implode(PHP_EOL, $lines), ENT_NOQUOTES);
  23.  
  24. // Send email and direct browser to confirmation page
  25. $valid = str_word_count(reset($_POST)) > 2;  //words in first field
  26. if ($valid)  //simplistic check to reduce spam
  27.    mail($sendTo, $subjectLine, $body, "From: $sendFrom");
  28. header("Location: $thanksUrl");
  29. ?>

Raw Paste


Login or Register to edit or fork this paste. It's free.