php form mail: send mail after display of confirmation page


/ Published in: PHP
Save to your folder(s)

the user sees the confirmation page immedeateley. this is helpful if the mail() function takes some time


Copy this code and paste it in your HTML
  1. <?
  2.  
  3.  
  4. ?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html><head><meta http-equiv="content-type" content="text/html;charset=utf-8">
  6. </head><body>
  7.  
  8. <?
  9. if (isset($_POST["go"])):
  10. ?>
  11.  
  12. <h2>Thank you for sending the form!</h2>
  13.  
  14. <?
  15.  
  16. global $body_for_callback;
  17. $body_for_callback = $_POST["name"] ." has filled in the form.";
  18.  
  19. function mail_callback() {
  20. global $body_for_callback;
  21. mail("[email protected]","Form result",$body_for_callback);
  22. }
  23. else:
  24. ?>
  25. <form id="orderform" action="#" method="post" name="form1">
  26. <input type="text" name="name">
  27. <input type="submit" name="go" value="send form">
  28. </form>
  29. <?
  30. endif;
  31. ?>
  32. </body></html>
  33. <?
  34. header("Connection: close");
  35. $size = ob_get_length();
  36. header("Content-Length: $size");
  37. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.