Guest User

Untitled

a guest
Mar 19th, 2018
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php //recipient
  2. $to = 'sbchamadiya.weapplinse@gmail.com';
  3. //sender
  4. $from = 'sbchamadiya.weapplinse@gmail.com';
  5. $fromName = 'Farmgo';
  6.  
  7. //email subject
  8. $subject = 'PHP Email with Attachment by Farmgo';
  9.  
  10. //attachment file path
  11. //$file = "codexworld.pdf";
  12. //$file = "send_mail_to_user_of_farmgo.php";
  13.  
  14. $file ="http://166.62.120.212/~anigo/foodapp/uploads/invoice/477.pdf";
  15.  
  16. //email body content
  17. $htmlContent = '<h1>PHP Email with Attachment by Farmgo</h1>
  18. <p>This email has sent from PHP script with attachment.</p>';
  19.  
  20. //header for sender info
  21. $headers = "From: $fromName"." <".$from.">";
  22.  
  23. //boundary
  24. $semi_rand = md5(time());
  25. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  26.  
  27. //headers for attachment
  28. $headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";
  29.  
  30. //multipart boundary
  31. $message = "--{$mime_boundary}n" . "Content-Type: text/html; charset="UTF-8"n" .
  32. "Content-Transfer-Encoding: 7bitnn" . $htmlContent . "nn";
  33.  
  34. //preparing attachment
  35. if(!empty($file) > 0){
  36. if(is_file($file)){
  37. $message .= "--{$mime_boundary}n";
  38. $fp = @fopen($file,"rb");
  39. $data = @fread($fp,filesize($file));
  40.  
  41. @fclose($fp);
  42. $data = chunk_split(base64_encode($data));
  43. $message .= "Content-Type: application/octet-stream; name="".basename($file).""n" .
  44. "Content-Description: ".basename($files[$i])."n" .
  45. "Content-Disposition: attachment;n" . " filename="".basename($file).""; size=".filesize($file).";n" .
  46. "Content-Transfer-Encoding: base64nn" . $data . "nn";
  47. }
  48. }
  49. $message .= "--{$mime_boundary}--";
  50. $returnpath = "-f" . $from;
  51.  
  52. //send email
  53. $mail = @mail($to, $subject, $message, $headers, $returnpath);
  54.  
  55. //email sending status
  56. echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1>";
Add Comment
Please, Sign In to add comment