Public paste
mail form!
By: Ruben | Date: Jan 15 2008 14:38 | Format: PHP | Expires: never | Size: 3.97 KB | Hits: 1321

  1. <?
  2. $mail_ontv = "emailadres@mail.nl";
  3. $mail = $_POST['mail'];
  4.  
  5. function checkmail($mail)
  6. {
  7.     $email_host = explode("@", $mail);
  8.     $email_host = $email_host['1'];
  9.     $email_resolved = gethostbyname($email_host);
  10.  
  11.     if ($email_resolved != $email_host && eregi("^[0-9a-z]([-_.~]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$",$mail))
  12.         $valid = 1;
  13.  
  14.     return $valid;
  15. }
  16.  
  17.  
  18. if (!$_POST['submit'] || $_POST['submit'] && (!$_POST['naam'] || !$_POST['adres']|| !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['telefoon']  || !$_POST['msggs']))
  19. {
  20.     if ($_POST['submit'] && (!$_POST['naam'] || !$_POST['adres'] || !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['telefoon'] || !$_POST['msggs']))  
  21.     {
  22.         echo "<p>U heeft niet alle velden ingevuld. Of u ";
  23.         echo "heeft een onjuist e-mail adres hebt ingevuld.<p>";
  24.     }
  25.      
  26.     // form + tabel
  27.     echo "<form method="POST" ACTION="" . $_SERVER['PHP_SELF'] . "">";
  28.     echo "<table cellpadding="0" cellspacing="0" class="contact">";
  29.      
  30.     // naam
  31.     echo "<tr><td>Naam:</td>";
  32.     echo "<td><input type="text" name="naam" value="" . $_POST['naam'] . "" size="23" /></td></tr>";
  33.      
  34.     // adres
  35.     echo "<tr><td>Adres:</td>";
  36.     echo "<td><input type="text" name="adres" value="" . $_POST['adres'] . "" size="23"  /></td></tr>";
  37.      
  38.     // telefoon
  39.     echo "<tr><td>E-mail:</td>";
  40.     echo "<td><input type="text" name="mail" value="" . $_POST['mail'] . "" size="23" /></td></tr>";
  41.      
  42.     // email
  43.     echo "<tr><td>Telefoon:</td>";
  44.     echo "<td><input type="text" name="telefoon" value="" . $_POST['telefoon'] . "" size="23" /></td></tr>";
  45.      
  46.     // Bericht
  47.     echo "<tr><td style="vertical-align: top;">Opmerking:</td>";
  48.     echo "<td><TEXTAREA name="msggs" ROWS="3" COLS="20">" . htmlentities($_POST['msggs']) . "</TEXTAREA></td></tr>";
  49.      
  50.     // button
  51.     echo "<tr><td>&nbsp;</td>";
  52.     echo "<td style="text-align: right;"><input type="submit" name="submit" value="Versturen" class="submit" /></td></tr>";
  53.      
  54.     // sluit form + tabel
  55.     echo "</table>";
  56.     echo "</form>";
  57. }
  58. // versturen naar
  59. else
  60. {      
  61.     // set datum
  62.     $datum = date("d.m.Y H:i");
  63.      
  64.     // set ip
  65.     $ip = $_SERVER['REMOTE_ADDR'];
  66.      
  67.     $inhoud_mail = "===================================================n";
  68.     $inhoud_mail .= "Ingevulde contact formuliern";
  69.     $inhoud_mail .= "===================================================nn";
  70.    
  71.     $inhoud_mail .= $_SERVER['SCRIPT_URI'] . "nn";
  72.  
  73.     $inhoud_mail .= "Naam: " . $_POST['naam'] . "n";
  74.     $inhoud_mail .= "Adres: " . $_POST['adres'] . "n";
  75.     $inhoud_mail .= "Telefoon: " . $_POST['telefoon'] . "n";
  76.     $inhoud_mail .= "E-mail adres: " . $_POST['mail'] . "n";
  77.     $inhoud_mail .= "Bericht:n";
  78.     $inhoud_mail .= $_POST['msggs'] . "nn";
  79.      
  80.     $inhoud_mail .= "Verstuurd op " . $datum . " via het ip " . $ip . "nn";
  81.      
  82.     $inhoud_mail .= "===================================================nn";
  83.    
  84.    
  85.     $headers = "From: " . $_POST['naam'] . " <" . $_POST['mail'] . ">";
  86.    
  87.     $headers = stripslashes($headers);
  88.     $headers = str_replace("n", "", $headers); // Verwijder n
  89.     $headers = str_replace("r", "", $headers); // Verwijder r
  90.     $headers = str_replace(""", "\"", str_replace("\", "\\", $headers)); // Slashes van quotes
  91.    
  92.    $_POST['telefoon'] = str_replace("n", "", $_POST['telefoon']); // Verwijder n
  93.    $_POST['telefoon'] = str_replace("r", "", $_POST['telefoon']); // Verwijder r
  94.    $_POST['telefoon'] = str_replace(""", "\"", str_replace("\", "\\", $_POST['telefoon'])); // Slashes van quotes
  95.    
  96.    mail($mail_ontv, substr($_POST['msggs'], 0 , 40), $inhoud_mail, $headers);
  97.    
  98.    echo "<p>Bericht verzonden. Wij nemen zo spoedig mogelijk contact met u op.";
  99.    
  100. }
  101. ?>