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 (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.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
 
Start new topic
Odpowiedzi (1 - 6)
buliq
post
Post #2





Grupa: Zarejestrowani
Postów: 559
Pomógł: 93
Dołączył: 4.03.2008
Skąd: Olsztyn

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


Jakieś błędy? Raportowanie błędów włączone? Na jakim poziomie?
Go to the top of the page
+Quote Post
zundap
post
Post #3





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

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


W przeglądarce nic nie wyskakuje ino ze wysłany wszystk odochodzi tyle ze treśc wiadmości to puste pole
gdzie jeszcze jakieś raporty błędów znajde ?
Go to the top of the page
+Quote Post
timon27
post
Post #4





Grupa: Zarejestrowani
Postów: 578
Pomógł: 69
Dołączył: 15.04.2007
Skąd: Wrocław

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


"Generlanie szukam czegoś prostego do wysyłania PDF z pliku"

To proponuję phpmailer.
Ilość kodu powinna spaść ci 10 krotnie (IMG:style_emoticons/default/smile.gif)
Dodanie załącznika będzie wtedy w 1 linijce i nie będzie czego zepsuć.
Go to the top of the page
+Quote Post
timon27
post
Post #5





Grupa: Zarejestrowani
Postów: 578
Pomógł: 69
Dołączył: 15.04.2007
Skąd: Wrocław

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


Nie lubi "public" wprowadzonego w php 5.
Czy mógłbyś wykonać ten kod:
Cytat
<?php
phpinfo();
?>

I odczytać mi którą wersję PHP masz?

Ten post edytował timon27 2.10.2013, 16:40:30
Go to the top of the page
+Quote Post
zundap
post
Post #6





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

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


PHP Version 4.4.9

System Linux s128.superhost.pl 2.6.18-308.4.1.el5 #1 SMP Tue Apr 17 17:08:00 EDT 2012 x86_64
Build Date May 6 2011 21:31:24

Juz pobieram cos pod 4.0

Super działa tylko jesze polskie znaki w tytule i treści wiadomości krzaki
  1.  
  2. $mail = new PHPMailer();
  3. $mail->FromName = "Nazwa nadawcy";
  4. $mail->From = "mail@nadawcy.pl";
  5. $mail->AddAddress('zundap@vp.pl');
  6. $mail->AddReplyTo("mail@zwrotny.pl","Nazwa adresu zwrotnego");
  7. $mail->Subject = "Tytul mśźća";
  8. $mail->IsHTML(true);
  9. $mail->Body = "Tresc maila. Można uzywać tagow HTML i styli CSS";
  10. $mail->AddAttachment("1.pdf");
  11.  
  12. if(!$mail->Send()) {
  13. echo "Mailer Error: " . $mail->ErrorInfo;
  14. } else echo "Sukces. Mail został wysłany poprawnie";;


Ten post edytował zundap 2.10.2013, 18:18:38
Go to the top of the page
+Quote Post
timon27
post
Post #7





Grupa: Zarejestrowani
Postów: 578
Pomógł: 69
Dołączył: 15.04.2007
Skąd: Wrocław

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


Php5 pojawiło się w 2003 - 10 lat temu!
Suport i naprawy php4 skończyły się w 2008.
Dalsze korzystanie z php4 jest niewygodne i jest luką w bezpieczeństwie strony.

W superhost w zakładce 'ustawienia' zmień php na najnowszą wersję.
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 24.08.2025 - 21:56