Guest User

Untitled

a guest
Oct 19th, 2017
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['email'])) {
  3.  
  4. // Sends Email
  5. $email_to = "name@email.com";
  6.  
  7. $email_subject = "Subject";
  8.  
  9. <form name="htmlform" method="post" action="html_form_send.php">
  10. <table width="450px">
  11. </tr>
  12. <tr>
  13. <td valign="top">
  14. <label for="first_name">First Name *</label>
  15. </td>
  16. <td valign="top">
  17. <input type="text" name="first_name" maxlength="50" size="30">
  18. </td>
  19. </tr>
  20.  
  21. <tr>
  22. <td valign="top"">
  23. <label for="last_name">Last Name *</label>
  24. </td>
  25. <td valign="top">
  26. <input type="text" name="last_name" maxlength="50" size="30">
  27. </td>
  28. </tr>
  29. <tr>
  30. <td valign="top">
  31. <label for="email">Email Address *</label>
  32. </td>
  33. <td valign="top">
  34. <input type="text" name="email" maxlength="80" size="30">
  35. </td>
  36.  
  37. </tr>
  38. <tr>
  39. <td valign="top">
  40. <label for="telephone">Telephone Number</label>
  41. </td>
  42. <td valign="top">
  43. <input type="text" name="telephone" maxlength="30" size="30">
  44. </td>
  45. </tr>
  46. <tr>
  47. <td valign="top">
  48. <label for="comments">Comments *</label>
  49. </td>
  50. <td valign="top">
  51. <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
  52. </td>
  53.  
  54. </tr>
  55. <tr>
  56. <td colspan="2" style="text-align:center">
  57. <input type="submit" value="Submit"> ( <a href="http://www.freecontactform.com/html_form.php">HTML Form</a> )
  58. </td>
  59. </tr>
  60. </table>
  61. </form>
  62.  
  63. <?php
  64. if(isset($_POST['email'])) {
  65.  
  66.  
  67. $email_to = "name@email.com";
  68.  
  69. $email_subject = "Subject";
  70.  
  71.  
  72. function died($error) {
  73. // your error code can go here
  74. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  75. echo "These errors appear below.<br /><br />";
  76. echo $error."<br /><br />";
  77. echo "Please go back and fix these errors.<br /><br />";
  78. die();
  79. }
  80.  
  81. // validation expected data exists
  82. if(!isset($_POST['first_name']) ||
  83. !isset($_POST['last_name']) ||
  84. !isset($_POST['email']) ||
  85. !isset($_POST['telephone']) ||
  86. !isset($_POST['comments'])) {
  87. died('We are sorry, but there appears to be a problem with the form you submitted.');
  88. }
  89.  
  90. $first_name = $_POST['first_name']; // required
  91. $last_name = $_POST['last_name']; // required
  92. $email_from = $_POST['email']; // required
  93. $telephone = $_POST['telephone']; // not required
  94. $comments = $_POST['comments']; // required
  95.  
  96. $error_message = "";
  97. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
  98. if(!preg_match($email_exp,$email_from)) {
  99. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  100. }
  101. $string_exp = "/^[A-Za-z .'-]+$/";
  102. if(!preg_match($string_exp,$first_name)) {
  103. $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  104. }
  105. if(!preg_match($string_exp,$last_name)) {
  106. $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  107. }
  108. if(strlen($comments) < 2) {
  109. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  110. }
  111. if(strlen($error_message) > 0) {
  112. died($error_message);
  113. }
  114. $email_message = "Form details below.nn";
  115.  
  116. function clean_string($string) {
  117. $bad = array("content-type","bcc:","to:","cc:","href");
  118. return str_replace($bad,"",$string);
  119. }
  120.  
  121. $email_message .= "First Name: ".clean_string($first_name)."n";
  122. $email_message .= "Last Name: ".clean_string($last_name)."n";
  123. $email_message .= "Email: ".clean_string($email_from)."n";
  124. $email_message .= "Telephone: ".clean_string($telephone)."n";
  125. $email_message .= "Comments: ".clean_string($comments)."n";
  126.  
  127.  
  128. // create email headers
  129. $headers = 'From: '.$email_from."rn".
  130. 'Reply-To: '.$email_from."rn" .
  131. 'X-Mailer: PHP/' . phpversion();
  132. @mail($email_to, $email_subject, $email_message, $headers);
  133. ?>
  134.  
  135. Thank you for your response.
  136.  
  137. <?php
  138. }
  139. die();
  140. ?>
  141.  
  142. $email_to = "name@email.com,abc@xyz.com,bdc@mnq.com, nnn@nnn.nnn";
  143.  
  144. <form action="script.php">
  145. <select name="to_email_index">
  146. <option value="0" selected>Support</option>
  147. <option value="1" selected>Feedback</option>
  148. </select>
  149. <input type="submit" value="Send"/>
  150. </form>
  151.  
  152. if (!isset($_GET['to_email_index']))
  153. exit("Error");
  154.  
  155. $to_email = "support@me.com";
  156. if ($_GET['to_email_index']=="1")
  157. $to_email = "feedback@me.com";
Add Comment
Please, Sign In to add comment