login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Contact formulieren > Contact met bijlage (makkelijk )

Contact met bijlage (makkelijk )

Auteur: Topdancer - 29 augustus 2006 - 20:29 - Gekeurd door: Wijnand - Hits: 24962 - Aantal punten: 3.00 (6 stemmen)





Het is heel simpel.

verander alleen de e-mail adres en sla hem op als contact.php

Code:
  1. <?php
  2. // Your e-mail adress:
  3. $mailto = "naam@sitenaam.nl";
  4.  
  5. # Maximum size of attachment in bytes:
  6. $max_attach_size = 500000;
  7.  
  8. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  9. <html>
  10. <head>
  11. <title>Formmailer</title>
  12. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  13.  
  14. </head>
  15. <body><?php
  16. /*if (empty($_POST['form_submitted']))
  17.  {
  18.   ?></font><p><font color="#FFFFFF">Please fill out the form:</font></p>
  19. <font color="#FFFFFF"><?php
  20.  }
  21. */
  22. if (isset($_POST["form_submitted"]))
  23. {
  24. $name = $_POST['name'];
  25. $email = $_POST['email'];
  26. $subject = $_POST['subject'];
  27. $text = $_POST['text'];
  28.  
  29. unset($errors);
  30. if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "e-mail address lijkt incorrect";
  31. if ($text == "") $errors[] = "Geen bericht geplaatst";
  32. if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Bijlage is te groot(".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - maximum size: ".number_format($max_attach_size/1000,0,",","")." KB";
  33.  
  34. if (empty($errors))
  35. {
  36. $text = stripslashes($text);
  37. $subject = stripslashes($subject);
  38. if ($name != "") $mail_name=$name; else $mail_name="Unknown";
  39. if ($subject != "") $mail_subject = $subject; else $mail_subject = "No subject";
  40. if ($email != "") $mail_email = $email; else $mail_email = "email@unknown.xyz";
  41. $ip = $_SERVER["REMOTE_ADDR"];
  42.  
  43. // if attachment, MIME-Mail:
  44. if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
  45. {
  46. // read and encode file:
  47. $datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
  48. $datei_content = chunk_split(base64_encode($datei_content),76,"\n");
  49. // Boundary:
  50. $boundary = md5(uniqid(rand()));
  51. // Mail-Header:
  52. $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
  53. $mail_header .= "X-Sender-IP: ".$ip."\n";
  54. $mail_header .= "MIME-Version: 1.0\n";
  55. $mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
  56. $mail_header .= "This is a multi-part message in MIME format.\n";
  57. // Mail-Text:
  58. $mail_header .= "--".$boundary;
  59. $mail_header .= "\nContent-Type: text/plain";
  60. $mail_header .= "\nContent-Transfer-Encoding: 8bit";
  61. $mail_header .= "\n\n".$text;
  62. // Attachment:
  63. $mail_header .= "\n--".$boundary;
  64. $mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
  65. $mail_header .= "\nContent-Transfer-Encoding: base64";
  66. $mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
  67. $mail_header .= "\n\n".$datei_content;
  68. // End:
  69. $mail_header .= "\n--".$boundary."--";
  70. // Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
  71. if (@mail($mailto,$mail_subject,"",$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
  72. }
  73. // no attachment, normal E-mail:
  74. else
  75. {
  76. $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
  77. $mail_header .= "X-Sender-IP: $ip\n";
  78. $mail_header .= "Content-Type: text/plain";
  79. if (@mail($mailto,$mail_subject,$text,$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
  80. }
  81.  
  82. // copy to sender:
  83. if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
  84. {
  85. if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Copy of the e-mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Copy of the e-mail:\n\n".$text;
  86. $header= "From: ".$mailto."\n";
  87. $header .= "X-Sender-IP: ".$ip."\n";
  88. $header .= "Content-Type: text/plain";
  89. @mail($email, $mail_subject, $copy_mail_text, $header);
  90. }
  91. }
  92. }
  93.  
  94. if (empty($sent))
  95. {
  96. if(isset($errors))
  97. {
  98. ?></font><p class="caution"><font color="#FFFFFF">Error:</font></p><ul>
  99. <font color="#FFFFFF"><?php foreach($errors as $f) { ?></font><li>
  100. <font color="#FFFFFF"><?php echo $f; ?></li><?php } ?></font></ul>
  101. <font color="#FFFFFF"><br /><?php
  102. }
  103.  
  104. ?></font><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
  105. <p><font color="#FFFFFF"><span class="style2"><font face="Verdana" size="2">
  106. Naam</font></span><font face="Verdana" size="2"><span class="style2">:</span><br />
  107. </font>
  108. </font><font color="#FFFFFF">
  109. <input name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
  110. <font face="Verdana" size="2">
  111. <br />
  112. <span class="style2">E-mail:</span><br />
  113. </font>
  114. </font><font color="#FFFFFF">
  115. <input name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
  116. <font face="Verdana" size="2">
  117. <br />
  118. <span class="style2">Onderwerp:</span><br />
  119. </font>
  120. </font><font color="#FFFFFF">
  121. <input name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="25" style="font-family: Verdana; border: 1px dashed #000000" />
  122. <font face="Verdana" size="2">
  123. <br />
  124. <span class="style2">Bericht:</span><br />
  125. </font>
  126. </font><font color="#FFFFFF">
  127. <textarea name="text" cols="25" rows="7" style="font-family: Verdana; border: 1px dashed #000000"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
  128. </textarea>
  129. <font face="Verdana" size="2">
  130. <br />
  131. <span class="style2">Bijlagen:</span><br />
  132. </font>
  133. </font><font color="#FFFFFF">
  134. <input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="16" style="font-family: Verdana; border: 1px dashed #000000"/>
  135. </font>
  136. </p>
  137. </p>
  138. <p><font face="Verdana"><font color="#FFFFFF"><input type="checkbox" name="copy" value="true" /></font><font size="2" color="#FFFFFF">
  139. <span class="style2">Kopietje naar jezelf sturen?</span> </font></font>
  140. <font color="#FFFFFF">
  141. <input type="submit" name="form_submitted" value="OK - Verzenden" style="font-family: Verdana; border: 1px dashed #000000" /></font><font face="Verdana" size="2" color="#FFFFFF">
  142. </font> </p>
  143. </div>
  144. </form><font color="#FFFFFF"><?php
  145. }
  146. else
  147. {
  148. if (empty($email)) { ?></font></font><font color="#FFFFFF"> </font>
  149. <p><font color="#FFFFFF"><b><font face="Verdana" size="1">Bedankt</font></b><font size="1" face="Verdana"><b>!</b><br />
  150. Je mail is verzonden alleen kan ik je niet terug mailen omdat je geen e-mail
  151. adres hebt ingevuld! </font></font></p>
  152. <font face="Verdana" size="1"><font color="#FFFFFF"><?php }
  153. else { ?></font></font><font color="#FFFFFF"> </font>
  154. <p><font color="#FFFFFF"><b><font face="Verdana" size="1">Bedankt</font></b><font size="1" face="Verdana"><b>!</b><br />
  155. Je bericht is met succes verzonden ik zal zo spoedig mogelijk terug mailen. </font>
  156. </font></p>
  157. <font face="Verdana" size="1" color="#FFFFFF"><?php }
  158. }
  159.  
  160.  
  161. ?>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (5)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.062s