Mail und Datenbankinhalte

  • Mail und Datenbankinhalte

    Hallo zusammen,

    lange nicht mehr hier gewesen:

    Neuer Tag, neues Problem:
    Vielleicht hat jemand einen Tipp für mich?

    Ich habe ein PHP Script welches mir inhalte aus einer Postgress Datenbank holt.
    Diese inhalte bereits ich als HTML Mail auf und will Sie jeden 2 Tag per Cronjob versenden lasssen.

    So gut so schön:

    So soll es aussehen, und so sieht es auch als PHP-Script aus:

    [Blockierte Grafik: http://www.brali.de/mail.jpg]

    Wenn ich das ganze nun per Mail versende, dann zeigt er mit zwar die Zahlenwerte, nicht aber die Netzwerke und aktulle notwendigen zertifizierungen.
    Ich lese die Netzwerke und Zertifizierungen im Quelltext aus weil ich heir eine schleife verwende.

    Abfrage der Nummernwerte, ausserhalb der Nachricht mit übergabeparameter:

    Quellcode

    1. $resultdoc = pg_query ( $dbconn , 'SELECT COUNT(lid) FROM omuser WHERE strdomain IS NOT NULL' );
    2. while ($row = pg_fetch_row($resultdoc)) {
    3. $totaldoc = $row[0];
    4. }


    und hier die abfrage der netzwerke (analog werden die zertifikate abgefragt)

    Quellcode

    1. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    2. <tbody><tr><?
    3. $resultzentrumm = pg_query ( $dbconn2 , 'SELECT * FROM xcrm_customerf0f75f0b WHERE str_fpzcoach_d988400f = '$user' AND b_gltigeszertifikat_4bdd43c7 IS NULL order by str_nameshorttext_b7277709 ASC');
    4. while ($row = pg_fetch_row($resultzentrumm)) {
    5. $gueltigeszertifikatv = $row[20];
    6. $gueltigeszertifikatn = $row[21];
    7. echo '<td style=\"padding: 3px 7px; font-size: 12px;\">$gueltigeszertifikatn $gueltigeszertifikatv</td>';
    8. echo '</tr>';
    9. }
    10. </tr>
    11. </tbody></table>
    Alles anzeigen

    wenn ich die mail so generiere, bekomme ich nur den ersten wert aus der datenbank angezeigt.

    wie baue ich am besten eine abfrage ausserhalb des mailbody, wo ich die werte so übergeben kann?

    Schweres thema, ich hoffe ich konnte es genügend ausdrücken.

    Lieben dank schonmal
  • Du hast also das Problem, dass du problemlos die Ausgabe aufbereiten kannst.
    Aber Probleme hast alles in eine Variable zu binden, damit du den Inhalt per Email verschicken kannst?

    Dann habe ich da eine Empfehlung...
    nutze deinen aktuellen Quellcode und arbeite mit Ausgabepuffern.

    Quellcode

    1. ob_start();
    2. // hier dein bisheriger Quelltext mit normalen Ausgaben
    3. echo "foo";
    4. $content = ob_get_contents();
    5. ob_end_clean();
    6. mail($recipient, $subject, $content);
    Alles anzeigen
  • Super Tipp,

    jedoch funktioniert das nur bedingt.

    Die Abfragen die in der While schleife abgefragt werden, werden gelöscht und nur der letzte Wert wird eingetragen. Wenn also die DB Abfrage 19 Ergebnisse liefert, dann werden in der While schleife auch alle 19 werte ausgegeben.

    Ich muss die abfrage also vor dem Mailtext starten, weil ich sonst nur die abfrage als htmltext angezeigt bekomme, dann aber wird nur der letzte Wert der 19 angezeigt.
    Auf dem Bild siehst du welche ergebnisse ich bekomme, wenn ich die abfrage in den quelltext packe.

    [Blockierte Grafik: http://www.brali.de/bild.jpg]

    Wie bekomme ich die 19 werte in die Mail? ich verzweifel noch - ;)
  • Kann es sein, dass du Syntaxfehler hast?
    das echo "} sieht schon verdächtig aus. Poste doch mal deine Datei.
    Es ist übrigens gute Praxis im ganzen Projekt nur ein einziges "echo" zu haben. Baue seine HTML Ausgabe doch erstmal so um, dass du nur eine Variable "$content" zusammenbaust und diese am Ende ausgibst.
    Dann gibts auch kein Problem mit der Mail.
  • d0nut schrieb:

    Kann es sein, dass du Syntaxfehler hast?


    Klar kann das sein, ich sehe es jedoch net:

    anbei mal der komplette Quelltext:

    Quellcode

    1. <?php
    2. //abfrage der IV Ųzte gesamt
    3. $resultdoc = pg_query ( $dbconn , 'SELECT COUNT(lid) FROM omuser WHERE strdomain IS NOT NULL' );
    4. while ($row = pg_fetch_row($resultdoc)) {
    5. $totaldoc = $row[0];
    6. }
    7. // Abfrage aller hinterlegten zertifikate
    8. $resultfpzzentrumm = pg_query ( $dbconn2 , "SELECT COUNT(lid) FROM xcrm_customerf0f75f0b WHERE str__d988400f = '$user' AND b_gltigeszertifikat_4bdd43c7 = 'True' ");
    9. while ($row = pg_fetch_row($resultfpzzentrumm)) {
    10. $gesamtzertifikate_ok = $row[0];
    11. // Abfrage aller nicht hinterlegten zertifikate
    12. $resultfpzzentrummmm = pg_query ( $dbconn2 , "SELECT COUNT(lid) FROM xcrm_customerf0f75f0b WHERE str__d988400f = '$user' AND b_inhaberboolean_20882121 ='True' AND b_fachlicherleiterboo_ca7c0d3f ='True' AND b_therapeutboolean_edf542ff = 'True' AND b_gltigeszertifikat_4bdd43c7 IS NULL");
    13. while ($row = pg_fetch_row($resultfpzzentrummmm)) {
    14. $gesamtzertifikate_un = $row[0];
    15. //Abfrage der aller zentren
    16. $resultfpzzentrum = pg_query ( $dbconn2 , "SELECT COUNT(lid) FROM xcrm_customerf0f75f0b WHERE b__b8a14d32 = 'True' ");
    17. while ($row = pg_fetch_row($resultfpzzentrum)) {
    18. $totalfpzzentren = $row[0];
    19. // Abfrage der betreuten Netzwerke & der gesamten IV Netzwerke
    20. $result = pg_query ( $dbconn , "SELECT COUNT(str_betreuer_a0a3afe3) FROM xdatagroup375c7b82 WHERE str_betreuer_a0a3afe3 = '$user' ");
    21. while ($row = pg_fetch_row($result)) {
    22. $netzwerkanzeigeee =$row[0];
    23. }}}}}}}
    24. // Abfrage der gültigen zertifikate
    25. $resultfpzzentrum10 = pg_query ( $dbconn2 , "SELECT * FROM xcrm_customerf0f75f0b WHERE d988400f = '$user' AND b_gltigeszertifikat_4bdd43c7 = 'False' order by str_nameshorttext_b7277709 ASC");
    26. while ($row = pg_fetch_row($resultfpzzentrum10)) {
    27. $gueltigeszertifikatv = $row[20];
    28. $gueltigeszertifikatn = $row[21]; }
    29. ?>
    30. <head>
    31. </head>
    32. <?
    33. $message.= "
    34. <div><div class=\"h5\">
    35. <div style=\"margin: 0pt; padding: 0pt; font-size: 12px; color: rgb(51, 51, 51);\">
    36. <div style=\"padding: 10px 0pt 0pt 10px; width: 580px; font-family: arial,helvetica,sans-serif;\">
    37. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    38. <tbody><tr>
    39. <td width=\"50%\" style=\"width: 100%\">
    40. <img alt=\"Logo\" longdesc=\"Logo\" src=\"https://wwwxxxxx.de/xxx/images/logo_kundenakte.gif\" width=\"289\" height=\"48\"></td>
    41. </tr>
    42. </tbody></table>
    43. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    44. <tbody><tr>
    45. <td width=\"50%\" style=\"width: 100%\">
    46. <span class=\"style1\"><br>
    47. Hallo</span><font style=\"font-family: arial,helvetica,sans-serif; font-size: 16px; color: rgb(0, 101, 103); font-weight: bold;\"> $user,</font><br>
    48. </font><span class=\"style3\">
    49. <font class=\"style4\">
    50. Wie jeden Montag, erhalten Sie heute Ihre Wochenübersicht</font></span><br>
    51. </td></tr>
    52. </tbody></table>
    53. <br><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    54. <tbody><tr>
    55. <td style=\"border: 1px solid rgb(0, 101, 103); padding: 1px;\">
    56. <table style=\"margin: 0pt; padding: 0pt; background-color: #f0f0f0; font-size: 11px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
    57. <tbody><tr height=\"28\">
    58. <td bgcolor=\"#f0f0f0\" width=\"200\" class=\"style9\"><strong>&nbsp; Zitat der Woche</strong></td>
    59. </tr>
    60. </tbody></table>
    61. </td>
    62. </tr>
    63. </tbody></table>
    64. <table style=\"font-size: 12px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    65. <tbody><tr>
    66. <td valign=\"bottom\" width=\"66%\" style=\"width: 99%\"><br>
    67. <font style=\"font-family: arial,helvetica,sans-serif;\"><script type=\"text/javascript\" src=\"http://www.zitate-online.de/zitatdestages.js\"></script></font> <br>
    68. <br>
    69. </td>
    70. </tr>
    71. </tbody></table>
    72. <img alt=\"\" border=\"0\" width=\"1\" height=\"1\"><br>
    73. </tbody></table>
    74. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    75. <tbody><tr>
    76. <td style=\"padding: 3px 7px; font-size: 12px;\">$gueltigeszertifikatv $gueltigeszertifikatn</td>
    77. </tr>
    78. </tbody></table>
    79. <br>
    80. <table style=\"border: 1px solid rgb(214, 214, 204); font-size: 12px;\" bgcolor=\"#f0f0f0\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    81. <tbody><tr valign=\"middle\">
    82. <td style=\"padding: 0pt 6px; white-space: nowrap; height: 20px;\"><strong>Keine Zertifikatangaben hinterlegt</strong></td>
    83. </tr>
    84. </tbody></table>
    85. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    86. <tbody><tr><?
    87. </tr>
    88. </tbody></table>
    89. <br>
    90. <table style=\"border: 1px solid rgb(214, 214, 204); font-size: 12px;\" bgcolor=\"#f0f0f0\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    91. <tbody><tr valign=\"middle\">
    92. <td style=\"padding: 0pt 6px; white-space: nowrap; height: 20px;\"><strong>Ihre
    93. aktuellen Impulsärzte</strong></td>
    94. </tr>
    95. </tbody></table>
    96. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"358\">
    97. <tbody><tr>
    98. <td style=\"padding: 3px 7px; font-size: 12px;\">Abfragefehler - Admin wurde benachrichtigt</td>
    99. </tr>
    100. </tbody></table>
    101. <br>
    102. </td>
    103. <td width=\"10\"></td>
    104. <td width=\"210\">
    105. <table style=\"border: 1px solid rgb(214, 214, 204); font-size: 12px;\" bgcolor=\"#f0f0f0\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
    106. <tbody><tr valign=\"middle\">
    107. <td style=\"height: 20px;\" class=\"style2\">Ihre Netzwerke</td>
    108. </tr>
    109. </tbody></table>
    110. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
    111. <tbody><tr>
    112. $result = pg_query ( $dbconn , 'SELECT * FROM xdatagroup375c7b82 WHERE str_betreuer_a0a3afe3 = '$user' order by str_netzwerk_baf2ba9d ASC' );
    113. while ($row = pg_fetch_row($result)){
    114. $netzwerkanzeige = $row[5];
    115. <td style=\"padding: 3px 7px; font-size: 12px;\">$netzwerkanzeige</td>
    116. </tr>
    117. }
    118. <tr>
    119. <td style=\"padding: 7px; font-size: 12px;\">&nbsp;</td>
    120. </tr>
    121. </tbody></table>
    122. <br>
    123. </td>
    124. </tr>
    125. </tbody></table>
    126. <table style=\"font-size: 12px; padding-bottom: 15px; clear: both;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    127. <tbody>
    128. </tbody></table>
    129. <table style=\"font-size: 12px; padding-bottom: 15px; clear: both;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    130. <tbody>
    131. </tbody></table>
    132. <table style=\"font-size: 12px; padding-bottom: 15px; clear: both;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    133. <tbody><tr valign=\"top\">
    134. <td width=\"360\">
    135. <br>
    136. </td>
    137. <td width=\"10\"></td>
    138. <td width=\"210\"></td>
    139. </tr>
    140. </tbody></table>
    141. <table style=\"font-size: 12px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"580\">
    142. <tbody><tr>
    143. <td>
    144. <div style=\"border-bottom: 1px solid rgb(216, 216, 216); padding: 0pt 0pt 15px;\">
    145. </div>
    146. </td>
    147. </tr>
    148. <tr>
    149. <td><p style=\"padding: 0.5em 0pt; font-family: arial,helvetica,sans-serif; color: rgb(156, 156, 156); font-size: 10px;\">
    150. &nbsp;xxx Version 1.15 // © 2009
    151. </p>
    152. <p style=\"padding: 0.5em 0pt; font-family: arial,helvetica,sans-serif; color: rgb(156, 156, 156); font-size: 10px; display: block; width: 580px;\">
    153. &nbsp;</p>
    154. </td>
    155. </tr>
    156. </tbody></table>
    157. </div>
    158. </div>
    159. </div></div></div><br>
    160. ";
    161. $to = "xxx@xxx.de";
    162. $subject = "xxx für $user";
    163. $xtra = "From: xx@xx.de (xxx)\r\n";
    164. $xtra .= "Content-Type: text/html\r\nContent-Transfer-Encoding: 8bit\r\n";
    165. $xtra .= "X-Mailer: PHP ". phpversion();
    166. mail($to,
    167. $subject,
    168. $message,
    169. $xtra);
    170. echo " mail versendet";
    171. ?>
    Alles anzeigen