Advertisement
gitlez

YA: Simple Html Email Form

Jul 4th, 2011
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4.     YA Link:
  5.         http://answers.yahoo.com/question/?qid=20110703175108AAWivtW
  6.  
  7.  
  8. Remember that most FREE servers have mail() disabled or are blacklisted from major mail exchange servers. For more info read: http://www.gitlez-ans.co.cc/question/3 for more info
  9.  
  10. */
  11.  
  12.  
  13. function cleanInput($i){
  14.     return str_replace(Array('to:','from:','bcc:','cc:','reply-to:'),'',trim($i));
  15. }
  16. if($_SERVER['REQUEST_METHOD'] === 'POST'){
  17.     if(strlen($_POST['to_email']) === 0 || strlen($_POST['from_email']) === 0){
  18.         die('Required Form Field(s) are missing. Please <a href="Javascript: history.go(-1);">Go Back</a> and correct the missing fields (Email Addresses).');
  19.     }
  20.     $email = Array();
  21.     $email['to'] = $_POST['to_name'] . ' <' . $_POST['to_email'] . '>';
  22.     $email['from'] = $_POST['from_name'] . ' <' . $_POST['from_email'] . '>';
  23.     $email['subject'] = $_POST['subject'];
  24.     $email['message'] = $_POST['message'];
  25.     print_r($email);
  26.     $email = array_map('cleanInput',$email);
  27.     if(mail($email['to'],$email['subject'],$email['message'],'From: ' . $email['from'] . "\r\n")){
  28.         die('Email Sent Successfully.');
  29.     }else{
  30.         die('Email Error');
  31.     }
  32. }
  33.  
  34. ?>
  35. <html>
  36.     <head>
  37.         <title>Simple Form Emailer</title>
  38.         <style type="text/css">
  39.             form {
  40.                 position: relative;
  41.                 margin: auto;
  42.                 width: 460px;
  43.             }
  44.         </style>
  45. <body>
  46.     <form method="POST">
  47.         <fieldset name="to">
  48.             <h3>Recipient</h3>
  49.             Name: <input type="text" name="to_name" /><br />
  50.             Email: <input type="text" name="to_email" />
  51.         </fieldset>    
  52.         <fieldset name="from">
  53.             <h3>Sender</h3>
  54.             Name: <input type="text" name="from_name" /><br />
  55.             Email: <input type="text" name="from_email" />
  56.         </fieldset>
  57.         <fieldset name="subject">
  58.             <h3>Subject</h3>
  59.             <input type="text" name="subject" style="width: 240px;" />
  60.         </fieldset>    
  61.         <fieldset name="message">
  62.             <h3>Message</h3>
  63.             <textarea cols="50" rows="8" name="message"></textarea>
  64.         </fieldset>
  65.         <input type="submit" value="Send Email" />
  66.     </form>
  67. </body>
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement