Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <form name="contactform" method="post" action="sendMail.php">
  2.  
  3. <table width="400px">
  4.  
  5. <tr>
  6.  
  7. <td valign="top">
  8.  
  9. <label for="first_name">First Name *</label>
  10.  
  11. </td>
  12.  
  13. <td valign="top">
  14.  
  15. <input type="text" name="first_name" maxlength="50" size="30">
  16.  
  17. </td>
  18.  
  19. </tr>
  20.  
  21. <tr>
  22.  
  23. <td valign="top">
  24.  
  25. <label for="last_name">Last Name </label>
  26.  
  27. </td>
  28.  
  29. <td valign="top">
  30.  
  31. <input type="text" name="last_name" maxlength="50" size="30">
  32.  
  33. </td>
  34.  
  35. </tr>
  36.  
  37. <tr>
  38.  
  39. <td valign="top">
  40.  
  41. <label for="email">Email *</label>
  42.  
  43. </td>
  44.  
  45. <td valign="top">
  46.  
  47. <input type="text" name="email" maxlength="80" size="30">
  48.  
  49. </td>
  50.  
  51. </tr>
  52.  
  53. <tr>
  54.  
  55. <td valign="top">
  56.  
  57. <label for="telephone">Phone</label>
  58.  
  59. </td>
  60.  
  61. <td valign="top">
  62.  
  63. <input type="text" name="telephone" maxlength="30" size="30">
  64.  
  65. </td>
  66.  
  67. </tr>
  68.  
  69. <tr>
  70.  
  71. <td valign="top">
  72.  
  73. <label for="comments">Comments *</label>
  74.  
  75. </td>
  76.  
  77. <td valign="top">
  78.  
  79. <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
  80.  
  81. </td>
  82.  
  83. </tr>
  84.  
  85. <tr>
  86.  
  87. <td colspan="2" style="text-align:center">
  88.  
  89. <input type="submit" value="SUBMIT">
  90.  
  91. </td>
  92.  
  93. </tr>
  94.  
  95. </table>
  96.  
  97. </form>
  98.  
  99. <?php
  100.  
  101. require 'PHPMailer-master/PHPMailerAutoload.php';
  102.  
  103. $mail = new PHPMailer;
  104.  
  105. $mail->isSMTP();
  106. $mail->Host = 'smtp.gmail.com';
  107. $mail->SMTPAuth = true;
  108. $mail->Username = 'myname@gmail.com';
  109. $mail->Password = 'H********';
  110. $mail->SMTPSecure = 'tls';
  111. $mail->Port = 587;
  112. $mail->SMTPDebug = 1;
  113.  
  114. $mail->From = 'myname@gmail.com';
  115. $mail->FromName = 'TEST';
  116. $mail->addAddress('myname@domain.com');
  117.  
  118. $errors = '';
  119.  
  120. if(empty($_POST['name']) ||
  121. empty($_POST['email']) ||
  122. empty($_POST['phone']) ||
  123. empty($_POST['message']))
  124. {
  125. $errors .= "n Error: all fields are required";
  126. }
  127. $name = $_POST['name'];
  128. $email_address = $_POST['email'];
  129. $phone = $_POST['phone'];
  130. $message = $_POST['message'];
  131. if (!preg_match(
  132. "/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i",
  133. $email_address))
  134. {
  135. $errors .= "n Error: Invalid email address";
  136. }
  137.  
  138. if( empty($errors))
  139. {
  140. $to = $myemail;
  141.  
  142.  
  143.  
  144. mail($to, $subject, $message, $headers);
  145.  
  146. $email_subject = "Request Additional Information: $name";
  147. $email_body = "You have received a new request for additional information. ".
  148. " Here are the details:n Name: $name n ".
  149. "Email: $email_addressn Phone: $phonen Message: n $message";
  150. $headers = "From: $myemailn";
  151. $headers .= "Reply-To: $email_address";
  152. mail($to,$email_subject,$email_body,$headers);
  153. //redirect to the 'thank you' page
  154. header('Location: contact-form-thank-you.html');
  155. }
  156.  
  157.  
  158. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement