Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message)
  4. {
  5. $file = $path.$filename;
  6. $file_size = filesize($file);
  7. $handle = fopen($file, "r");
  8. $content = fread($handle, $file_size);
  9. fclose($handle);
  10. $content = chunk_split(base64_encode($content));
  11. $uid = md5(uniqid(time()));
  12. $header = "From: ".$from_name." <".$from_mail.">\r\n";
  13. $header .= "Reply-To: ".$replyto."\r\n";
  14. $header .= "MIME-Version: 1.0\r\n";
  15. $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  16. $header .= "This is a multi-part message in MIME format.\r\n";
  17. $header .= "--".$uid."\r\n";
  18. $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  19. $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  20. $header .= $message."\r\n\r\n";
  21. $header .= "--".$uid."\r\n";
  22. $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  23. $header .= "Content-Transfer-Encoding: base64\r\n";
  24. $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  25. $header .= $content."\r\n\r\n";
  26. $header .= "--".$uid."--";
  27. if (mail($mailto, $subject, "", $header)) {
  28. echo "mail send ... OK"; // or use booleans here
  29. } else {
  30. echo "mail send ... ERROR!";
  31. }
  32. }
  33.  
  34. $my_file = "somefile.zip";
  35. $my_path = "/your_path/to_the_attachment/";
  36. $my_name = "Olaf Lederer";
  37. $my_mail = "my@mail.com";
  38. $my_replyto = "my_reply_to@mail.net";
  39. $my_subject = "This is a mail with attachment.";
  40. $my_message = "Hallo,rndo you like this script? I hope it will help.rnrngr. Olaf";
  41. mail_attachment($my_file, $my_path, "recipient@mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement