Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Wysyałanie e-mail z załacznikiem PDF
zundap
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 1.10.2005

Ostrzeżenie: (0%)
-----


Witam mma taki skrytp ale nie wiem dlaczego nie wyświetla mi się treść w wiadomości questionmark.gifquestionmark.gif
Generlanie szukam czegoś prostego do wysyłania PDF z pliku

  1. function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false)
  2. {
  3. $eol="\r\n";
  4. $mime_boundary=md5(time());
  5.  
  6. # Common Headers
  7. $headers .= 'From: MyName<'.$fromaddress.'>'.$eol;
  8. $headers .= 'Reply-To: MyName<'.$fromaddress.'>'.$eol;
  9. $headers .= 'Return-Path: MyName<'.$fromaddress.'>'.$eol; // these two to set reply address
  10. $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  11. $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
  12.  
  13. # Boundry for marking the split & Multitype Headers
  14. $headers .= 'MIME-Version: 1.0'.$eol;
  15. $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
  16.  
  17. $msg = "";
  18.  
  19. if ($attachments !== false)
  20. {
  21.  
  22. for($i=0; $i < count($attachments); $i++)
  23. {
  24. if (is_file($attachments[$i]["file"]))
  25. {
  26. # File for Attachment
  27. $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
  28.  
  29. $handle=fopen($attachments[$i]["file"], 'rb');
  30. $f_contents=fread($handle, filesize($attachments[$i]["file"]));
  31. $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
  32. fclose($handle);
  33.  
  34. # Attachment
  35. $msg .= "--".$mime_boundary.$eol;
  36. $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
  37. $msg .= "Content-Transfer-Encoding: base64".$eol;
  38. $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
  39. $msg .= $f_contents.$eol.$eol;
  40.  
  41. }
  42. }
  43. }
  44.  
  45. # Setup for text OR html
  46. $msg .= "Content-Type: multipart/alternative".$eol;
  47.  
  48. # Text Version
  49. $msg .= "--".$mime_boundary.$eol;
  50. $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  51. $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  52. $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  53.  
  54. # HTML Version
  55. $msg .= "--".$mime_boundary.$eol;
  56. $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  57. $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  58. $msg .= $body.$eol.$eol;
  59.  
  60. # Finished
  61. $msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
  62.  
  63. # SEND THE EMAIL
  64. ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
  65. mail($emailaddress, $emailsubject, $msg, $headers);
  66. ini_restore(sendmail_from);
  67. echo "mail send";
  68. }
  69.  
  70.  
  71. # To Email Address
  72. $emailaddress="to@address.com";
  73.  
  74. # From Email Address
  75. $fromaddress = "from@address.com";
  76.  
  77. # Message Subject
  78. $emailsubject="This is a test mail with some attachments";
  79.  
  80. # Use relative paths to the attachments
  81. $attachments = Array(
  82. Array("file"=>"../../test.doc", "content_type"=>"application/msword"),
  83. Array("file"=>"../../123.pdf", "content_type"=>"application/pdf")
  84. );
  85.  
  86. # Message Body
  87. $body="This is a message with <b>".count($attachments)."</b> attachments and maybe some <i>HTML</i>!";
  88.  
  89. send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments);
  90.  


Ten post edytował zundap 1.10.2013, 15:13:02
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 21:55