Guest User

Untitled

a guest
Mar 19th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. $name = "myname";
  4. $to = "receive@gmail.com";
  5. $email = "sender@gmail.com";
  6. $from = "myname";
  7. $subject = "Here is your attachment";
  8. $mainMessage = "Hi, here's the file.";
  9. $fileatt = $_SERVER['DOCUMENT_ROOT']."/xxx/ticket.pdf";
  10.  
  11. $fileatttype = "application/pdf";
  12. $fileattname = "ticket.pdf";
  13. $headers = "From: $from";
  14.  
  15. // File
  16. $file = fopen($fileatt, 'rb');
  17. $data = fread($file, filesize($fileatt));
  18. fclose($file);
  19.  
  20. // This attaches the file
  21. $semi_rand = md5(time());
  22. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  23. $headers .= "nMIME-Version: 1.0n" .
  24. "Content-Type: multipart/mixed;n" .
  25. " boundary="{$mime_boundary}"";
  26.  
  27. $message = "This is a multi-part message in MIME format.nn" .
  28. "-{$mime_boundary}n" .
  29. "Content-Type: text/html; charset="iso-8859-1n" .
  30. "Content-Transfer-Encoding: 7bitnn" .
  31. $mainMessage . "nn";
  32.  
  33. $data = chunk_split(base64_encode($data));
  34. $message .= "--{$mime_boundary}n" .
  35. "Content-Type: {$fileatttype};n" .
  36. " name="{$fileattname}"n" .
  37. "Content-Disposition: attachment;n" .
  38. " filename="{$fileattname}"n" .
  39. "Content-Transfer-Encoding: base64nn" .
  40. $data . "nn" .
  41. "-{$mime_boundary}-n";
  42.  
  43. // Send the email
  44. if(mail($to, $subject, $message, $headers)) {
  45. echo "The email was sent.";
  46. }
  47. else {
  48. echo "There was an error sending the mail.";
  49. }
  50.  
  51.  
  52. ?>
Add Comment
Please, Sign In to add comment