Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> sender e-mail
vojtasek
post 20.12.2011, 09:25:02
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 6.07.2009

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


Witam mam taki mały skrypt do wysyłania poczty e-mail na konta, które przed wysłaniem zaczytywane są do formularza z bazy danych.

  1. <?php
  2. include ("db.php");
  3. //Poberz adresy E-mail z bazy
  4. $sqlquery = "select * from person where email is not NULL";
  5. $result = mysql_query($sqlquery);
  6. $numrows = mysql_num_rows($result);
  7.  
  8. for($x=0; $x<$numrows; $x++){
  9. $result_row = mysql_fetch_row($result);
  10. $oneemail = $result_row[8];
  11. $emaillist .= $oneemail."\n";
  12. }
  13.  
  14. if ($action=="send"){ $message = urlencode($message);
  15. $message = ereg_replace("%5C%22", "%22", $message);
  16. $message = urldecode($message);
  17. $message = stripslashes($message);
  18. $subject = stripslashes($subject);
  19. }
  20. ?>


następnie jest kod HTML wyświetlanego formularza.


wszystko jest ładnie do momentu wysłania.

Wysyłam za pomocą takiego kodu:

  1. <?php
  2. if ($action=="send"){
  3. if (!$from && !$subject && !$message && !$emaillist){
  4. echo"</br><center><font color='red'><b>Proszę uzupełnić wszystkie wymagane pola !!!</b></font></center>";
  5. exit;
  6. }
  7. $allemails = split("\n", $emaillist);
  8. $numemails = count($allemails);
  9. If ($file_name){
  10. if (!file_exists($file)){
  11. die("Plik nie może być skopiowany na serwer");
  12. }
  13. $content = fread(fopen($file,"r"),filesize($file));
  14. $content = chunk_split(base64_encode($content));
  15. $uid = strtoupper(md5(uniqid(time())));
  16. $name = basename($file);
  17. }
  18.  
  19. for($xx=0; $xx<$amount; $xx++){
  20. for($x=0; $x<$numemails; $x++){
  21. $to = $allemails[$x];
  22. if ($to){
  23. $to = ereg_replace(" ", "", $to);
  24. $message = ereg_replace("&email&", $to, $message);
  25. $subject = ereg_replace("&email&", $to, $subject);
  26. print "Wysyła e-mail do $to.......";
  27. flush();
  28. $header = "From: $realname <$from>\r\nReply-To: $replyto\r\n";
  29. $header .= "MIME-Version: 1.0\r\n";
  30. $header .= "Content-type: text/html; charset=UTF-8\r\n";
  31. If ($file_name) $header .= "Content-Type: multipart/mixed; boundary=$uid\r\n";
  32. If ($file_name) $header .= "--$uid\r\n";
  33. $header .= "Content-Type: text/$contenttype\r\n";
  34. $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
  35. $header .= "$message\r\n";
  36. If ($file_name) $header .= "--$uid\r\n";
  37. If ($file_name) $header .= "Content-Type: $file_type; name=\"$file_name\"\r\n";
  38. If ($file_name) $header .= "Content-Transfer-Encoding: base64\r\n";
  39. If ($file_name) $header .= "Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n";
  40. If ($file_name) $header .= "$content\r\n";
  41. If ($file_name) $header .= "--$uid--";
  42. mail($to, $subject, "", $header);
  43. print "ok<br>";
  44. flush();
  45. }
  46. }
  47. }
  48. }
  49. ?>



Dlaczego po zatwierdzeniu wysyłania wysyła mi podwójnie do na każdy mail z bazy?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
askone
post 20.12.2011, 10:10:15
Post #2





Grupa: Zarejestrowani
Postów: 654
Pomógł: 121
Dołączył: 27.10.2007
Skąd: Poznań, Łódź

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


A co masz w zmiennej $amount?? Bo z tego co widzę wysyłanie maili masz ujęte w podwójnie zagnieżdżonej pętli...


--------------------
Kliknij jeśli moja odpowiedź Ci pomogła.
askone.pl
Go to the top of the page
+Quote Post
vojtasek
post 20.12.2011, 11:06:04
Post #3





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 6.07.2009

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


w $amount mam wartość z formularza liczba do wyłania i mam ustawiona wartość 1

chyba się rozwiązało ustawiłem $amount na wartość pustą przy ładowaniu formularza. Jak klient wpisze sobie wartość 1 to wysyła 1 raz jak 2 to dwa itd...


Ale chciałbym by po wysłaniu i wyświetleniu informacji podsumowującej tworzyło loga wysłania i czyściło formularz...jak to mogę zrobić?

Ten post edytował vojtasek 20.12.2011, 10:46:01
Go to the top of the page
+Quote Post
Uriziel01
post 20.12.2011, 11:15:15
Post #4





Grupa: Zarejestrowani
Postów: 307
Pomógł: 37
Dołączył: 9.11.2010
Skąd: Zielona Góra

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


Log możesz zapisać do bazy danych lub do pliku. Nie widze tutaj formularza który chcesz rzekomo wyczyścić ale zrobisz to przez JS jeżeli masz na mysliczyszczenie dynamiczne. Nie widząc całego kodu ciężko powiedzieć.

Ten post edytował Uriziel01 20.12.2011, 11:15:43
Go to the top of the page
+Quote Post
vojtasek
post 20.12.2011, 12:05:58
Post #5





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 6.07.2009

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


  1. <form name="form1" method="post" action="" enctype="multipart/form-data" id="contactform"><br />
  2. <table width="800" border="0">
  3. <tr>
  4.  
  5. <td width="200">
  6. <div align="right">Twój E-mail:</div>
  7. </td>
  8.  
  9. <td width="250">
  10. <input type="text" name="from" value="proart@poczta.onet.pl" size="30" disabled="disabled" />
  11. </td>
  12.  
  13. <td width="200">
  14. <div align="right">Twoja nazwa:</div>
  15. </td>
  16.  
  17. <td width="278">
  18. <input type="text" name="realname" value="PROArt" size="30" disabled="disabled" />
  19. </font>
  20. </td>
  21. </tr>
  22. <tr>
  23. <td width="200">
  24. <div align="right">Odeślij - do:</font></div>
  25. </td>
  26. <td width="219">
  27. <input type="text" name="replyto" value="<?php echo $replyto; ?>" size="30" />
  28. </td>
  29. <td width="200">
  30. <div align="right"> Dodaj plik/zdjęcie:</div>
  31. </td>
  32. <td width="278">
  33. <input type="file" name="file" size="24" />
  34. </td>
  35. </tr>
  36. <tr>
  37. <td width="200">
  38. <div align="right">Temat:</div>
  39. </td>
  40. <td colspan="3" width="703">
  41. <input type="text" name="subject" value="<?php echo $subject; ?>" size="90" />
  42. </font>
  43. </td>
  44. </tr>
  45. <tr valign="top">
  46. <td colspan="3" width="520">Treść :</td>
  47. <td width="278">Odbiorca E-mail / Wysyłane do :</td>
  48. </tr>
  49. <tr valign="top">
  50. <td colspan="3" width="520">
  51. <textarea name="message" cols="90" rows="10"><?php echo $message; ?></textarea><br />
  52. <input type="radio" name="contenttype" value="plain" checked="checked" /> Plain
  53. <input type="radio" name="contenttype" value="html" /> HTML
  54. <input type="hidden" name="action" value="send" /><br />
  55. Liczba do wysłania: <input type="text" name="amount" value="0" size="10" /><br />
  56. Czas skryptu(w sekundach, 0 bez limitu) <input type="text" name="timelimit" value="0" size="10" />
  57. <input type="submit" value="Wyślij E-mail" /> <input type="reset" value="Wyczyść formularz">
  58. </td>
  59. <td width="278">
  60. <textarea name="emaillist" cols="50" rows="10"><?php echo $emaillist; ?></textarea>
  61. </td>
  62. </tr>
  63. </table>
  64.  
  65.  
  66.  
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 13.08.2025 - 23:07