Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wysyłanie maila z umowa ktorej nazwa jest caly czas zmieniana.
zaszekk
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 11.01.2023

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


Witam, mam pytanie nie wiem za bardzo jak to pogodzić, mianowicie mam edytor ktory edytuje mi plik podstawowy i zapisuje go z unikalnym id, a chce za kazdym razem po kliknieciu przycisku zeby wysylalo maila z tym plikiem. wstawie kod od wysylania maila (nie skonczony) i kod edytora
  1. <?php srand((double)microtime()*1000000);
  2. $znacznik = md5(uniqid(rand()));
  3.  
  4. // dane o odbiorcy, nadawcy i załączniku
  5. $odbiorca = $_POST['imie_nazwisko'];
  6. $tytul = "Przesyłamy umowe.";
  7. $nadawca_imie = "Moyen";
  8. $nadawca_email = "moyen@moyenks.pl";
  9. $plik = "umowa%.docx";
  10. $typpliku = "image/gif";
  11. $nazwapliku = "mojelogo.gif";
  12.  
  13. // treść listu
  14. $tresclistu = "
  15. Witaj,
  16.  
  17. wysyłam Ci list z załącznikiem!
  18. ";
  19.  
  20. // definicja nagłówków
  21. $naglowki = "From: $nadawca_imie <$nadawca_email>\n";
  22. $naglowki .= "MIME-Version: 1.0\n";
  23. $naglowki .= "Content-Type: multipart/mixed;\n";
  24. $naglowki .= "\tboundary=\"___$znacznik==\"";
  25.  
  26. // nagłówki listu
  27. $tresc="--___$znacznik==\n";
  28. $tresc .="Content-Type: text/plain; charset=\"iso-8859-2\"\n";
  29. $tresc .="Content-Transfer-Encoding: 8bit\n";
  30. $tresc .="\n$tresclistu\n";
  31.  
  32. // nagłówki i obsługa załącznika
  33. $tresc .="--___$znacznik==\n";
  34. $tresc .="Content-Type: $typpliku\n";
  35. $tresc .="Content-Disposition: attachment;\n";
  36. $tresc .=" filename=\"$nazwapliku\"\n";
  37. $tresc .="Content-Transfer-Encoding: base64\n\n";
  38. $f = fopen($plik,"r");
  39. $dane = fread($f,filesize($plik));
  40. fclose($f);
  41. $tresc .= chunk_split(base64_encode($dane));
  42. $tresc .="--___$znacznik==--\n";
  43.  
  44. // wysłanie listu
  45. mail($odbiorca,$tytul,$tresc,$naglowki);
  46. ?>

  1. $template_file_name = 'umowa.docx';
  2.  
  3. $rand_no = uniqid(date('d-m-Y'),230);
  4. $fileName = "umowa" . $rand_no . ".docx";
  5.  
  6. $folder = "umowa";
  7. $full_path = $folder . '/' . $fileName;
  8.  
  9. try
  10. {
  11. if (!file_exists($folder))
  12. {
  13. mkdir($folder);
  14. }
  15.  
  16. //Copy the Template file to the Result Directory
  17. copy($template_file_name, $full_path);
  18.  
  19. // add calss Zip Archive
  20. $zip_val = new ZipArchive;
  21.  
  22. //Docx file is nothing but a zip file. Open this Zip File
  23. if($zip_val->open($full_path) == true)
  24. {
  25. // In the Open XML Wordprocessing format content is stored.
  26. // In the document.xml file located in the word directory.
  27.  
  28. $key_file_name = 'word/document.xml';
  29. $message = $zip_val->getFromName($key_file_name);
  30.  
  31. $timestamp = date('d-m-Y');
  32. $timestamp2 = date('d-m-Y');
  33.  
  34. // this data Replace the placeholders with actual values
  35. $message = str_replace("{name}", "$imie_nazwisko1", $message);
  36. $message = str_replace("{city}", "$miasto1", $message);
  37. $message = str_replace("{date}", $timestamp, $message);
  38. $message = str_replace("{dd}", $timestamp2 , $message);
  39. $message = str_replace("{kodpocztowy}", "$kodpocztowy1", $message);
  40. $message = str_replace("{ulica}", "$ulicanr1", $message);
  41. $message = str_replace("{sposob}", "$sposob1", $message);
  42. $message = str_replace("{item}", "$model1", $message);
  43. $message = str_replace("{cash}", "$suma1", $message);
  44.  
  45.  
  46.  
  47. //Replace the content with the new content created above.
  48. $zip_val->addFromString($key_file_name, $message);
  49. $zip_val->close();
  50. }
  51. }
  52. catch (Exception $exc)
  53. {
  54. $error_message = "Error creating the Word Document";
  55. var_dump($exc);
  56. }
Go to the top of the page
+Quote Post

Posty w temacie


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.12.2025 - 13:22