login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Contact formulieren > Mail met bijlage

Mail met bijlage

Auteur: Clanscript.be - 04 september 2004 - 20:43 - Gekeurd door: Dennisvb - Hits: 21086 - Aantal punten: 1.67 (3 stemmen)




Deze code zal je toelaten om emails te verzenden via php, en indien nodig een bijlage toevoegen !!! Simpel in gebruik.

Code:
  1. <?php
  2. $fileatt = ""; // Path to the file
  3. $fileatt_type = "application/octet-stream"; // File Type
  4. $fileatt_name = ""; // Filename that will be used for the file as the attachment
  5.  
  6. $email_from = ""; // Who the email is from
  7. $email_subject = ""; // The Subject of the email
  8. $email_message = ""; // Message that the email has in it
  9.  
  10. $email_to = ""; // Who the email is too
  11.  
  12. $headers = "From: $email_from";
  13.  
  14. $file = fopen($fileatt,'rb');
  15. $data = fread($file,filesize($fileatt));
  16. fclose($file);
  17.  
  18. $semi_rand = md5(time());
  19. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  20.  
  21. $headers .= "\nMIME-Version: 1.0\n" .
  22. "Content-Type: multipart/mixed;\n" .
  23. " boundary=\"{$mime_boundary}\"";
  24.  
  25. $email_message = "This is a multi-part message in MIME format.\n\n" .
  26. "--{$mime_boundary}\n" .
  27. "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  28. "Content-Transfer-Encoding: 7bit\n\n" .
  29. $email_message . "\n\n";
  30.  
  31. $data = chunk_split(base64_encode($data));
  32.  
  33. $email_message .= "--{$mime_boundary}\n" .
  34. "Content-Type: {$fileatt_type};\n" .
  35. " name=\"{$fileatt_name}\"\n" .
  36. //"Content-Disposition: attachment;\n" .
  37. //" filename=\"{$fileatt_name}\"\n" .
  38. "Content-Transfer-Encoding: base64\n\n" .
  39. $data . "\n\n" .
  40. "--{$mime_boundary}--\n";
  41.  
  42. $ok = @mail($email_to, $email_subject, $email_message, $headers);
  43.  
  44. if($ok) {
  45. echo "<font face=verdana size=2>The file was successfully sent!</font>";
  46. } else {
  47. die("Sorry but the email could not be sent. Please go back and try again!");
  48. }
  49. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

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