Share Pastebin
Guest
Public paste!

Contact.php + formmail.php

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 2.44 KB | Hits: 167 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1.                                 <h3>Contact Form:</h3>
  2.                                 <form action="php/formmail.php" method="post" name="Contact">
  3.  
  4.                  <table cellspacing="0" cellpadding="11" border="0" bgcolor="#0084ff" align="center" class="kantlinje">
  5.                  <tbody><tr>
  6.                  <td>Name:<br>
  7.                      <input type="text" class="skugga" size="40" name="name">
  8.                      <br>
  9.                      <br>
  10.                      Subject:<br>
  11.                     <input type="text" size="40" class="skugga" name="subject">
  12.                     <br>
  13.                     <br>
  14.                     <br>
  15.                     Email:<br>
  16.                     <input type="text" size="40" class="skugga" name="email">
  17.                     <br>
  18.                     <br>
  19.                     Message:<br>
  20.                     <textarea class="skugga" rows="7" cols="40" name="message"></textarea>
  21.                     <br>
  22.                     <br><input type="submit" value="Send Message" name="submit">
  23.                  </td>
  24.             </tr>
  25.     </tbody></table>
  26. </form>
  27.  
  28. Put this in your page, then you need this as well,
  29.  
  30. <?php
  31.  
  32. // anger en variabel som kan lagra de eventuella felaktigheterna
  33. $errors = array();
  34.  
  35. // kontrollera om ett Namn angivits
  36. if (!$_POST["name"])
  37. $errors[] = "- your name";
  38.  
  39. // kontrollera om ett Ämne angivits
  40. if (!$_POST["subject"])
  41. $errors[] = "- subject in subjectrow";
  42.  
  43. // kontrollera om en Epostadress angivits
  44. if (!$_POST["email"])
  45. $errors[] = "- your email";
  46.  
  47. // kontrollera om ett Meddelande angivits
  48. if (!$_POST["message"])
  49. $errors[] = "- no message was written!";
  50.  
  51. // om felaktig information finns visas detta meddelande
  52. if (count($errors)>0){
  53. echo "<strong>The following information must be filled in to send the form:</strong><br />";
  54. foreach($errors as $fel)
  55. echo "$fel <br />";
  56. echo "<br />Type in what is missing, and send it again Thanks! <br />";
  57. echo "<a href='javascript:history.go(-1)'>klicka här för att komma tillbaka till formuläret</a>";
  58. }
  59.  
  60. else {
  61. // formuläret är korrekt ifyllt och informationen bearbetas
  62. $to = "robinhubner@gmail.com";
  63. $from = $_POST["email"];
  64. $subject = $_POST["subject"];
  65. $name = $_POST["name"];
  66. $message = $_POST["message"];
  67.  
  68. if (mail($to, $subject, $message ,"From: $name <$from>"))
  69. echo nl2br("<h2>Your message was sent!</h2>
  70. <b>recipient:</b> $to
  71. <b>subject:</b> $subject
  72. <b>message:</b>
  73. $message
  74. ");
  75.  
  76.      else
  77.      echo "Unable to send your message";
  78. }
  79.  
  80. ?>