2017-12-13 2 views
-1

mir eine E-Mail-Funktion und in meinem $mail->Body ich html & PHP-Code in meinem $mail->Body aber ich nicht führen lassen, dass ich will, ich glaube, mein html & PHP-Code ist noch Fehler, aber ich bekomme keine Fehlermeldung, so dass ich nicht weiß, was ist falsch mit meinem HTML & PHP-Code. kann ich eine Fehlermeldung für meinen Inhalt $mail->Body zeigen. Ich glaube, meine Code-Fehler, denn wenn ich einfachen Code verwenden, um Daten in der Datenbank zeigt, ichzeigt Fehlermeldung und zeigt Abfrageer in html-Typ E-Mail

E-Mail senden geschaffen, dies ist mein Code:

$query = mysql_query("this is my query"); 

    while ($data = mysql_fetch_assoc($query)) { 

--I show my query result in `$mail->Body`-- 


$mail = new PHPMailer(); 
$mail->IsSMTP(); 
      $mail->Host = "172.16.x.xx"; //my company host 
      $mail->PORT = "25"; 
      $mail->SMTPAuth = true; 
      $mail->Username = "[email protected]"; //my company email 
      $mail->Password = "mypassword"; // SMTP password 
      $mail->IsHTML(true); 

      $mail->From = "[email protected]"; 
      $mail->FromName = "ITCareHelpdesk ACC"; 
      $mail->AddAddress("[email protected]");        
      $mail->mailtype = "html"; 
      $mail->Subject = "Weekly monitoring tiket open ITcare"; 
    $mail->Body =" 
    <table border=1> 
     <tr> 
     <th>Ticket ID</th> 
     <th>Kategori</th> 
     <th>Sub kategori</th>       
     <th>Deskripsi</th>       
     <th>NPK</th>       
     <th>Nama</th>       
     <th>Posisi</th>       
     <th>Branch</th>       
     <th>Waktu mulai</th>       
     <th>Group section</th>       
     <th>Pic Handle</th> 
     <th>Pic Group Section</th>             
     </tr> 


     <tr $color> 
      <td>$data[TICKET_ID]</td> 
      <td>$data[kategori]</td> 
      <td>$data[sub_sub_sub_kategori]</td> 
      <td>$data[description]</td> 
      <td>$data[npk]</td> 
      <td>$data[customer_name]</td> 
      <td>$data[position]</td> 
      <td>$data[branch]</td> 
      <td>$data[start_IT]</td> 
      <td>$data[group_section]</td> 
      <td>$data[pic_handle]</td> 
      <td>$data[pic_group_section]</td> 

     </tr> 

     </table>"; 
    } 

Ich versuche es zu senden und ich bekomme E-Mail, aber meine Frage Ergebnis zeigt nur 1 Zeile und eine andere Zeile wird nicht angezeigt.

+0

hinzufügen vollständige E-Mail Code –

+0

Ich habe @AmitGupta – pahlevi

+0

Was in E-Mail kommt? –

Antwort

0

Ihr E-Mail-Objekt muss nicht immer wieder in while-Schleife wiederholen werden. Es muss nur kommen einmal in Ihrer Seite und in while-Schleife Sie alle Details von mail- $ erhalten müssen> Body wie unten:

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->Host = "172.16.x.xx"; //my company host 
$mail->PORT = "25"; 
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]"; //my company email 
$mail->Password = "mypassword"; // SMTP password 
$mail->IsHTML(true); 

$mail->From = "[email protected]"; 
$mail->FromName = "ITCareHelpdesk ACC"; 
$mail->AddAddress("[email protected]");        
$mail->mailtype = "html"; 
$mail->Subject = "Weekly monitoring tiket open ITcare"; 

$query = mysql_query("this is my query"); 
$body .= "<table border=1>"; 
while ($data = mysql_fetch_assoc($query)) { 
     // I show my query result in `$mail->Body` 
$body .= " 
    <tr> 
    <th>Ticket ID</th> 
    <th>Kategori</th> 
    <th>Sub kategori</th>       
    <th>Deskripsi</th>       
    <th>NPK</th>       
    <th>Nama</th>       
    <th>Posisi</th>       
    <th>Branch</th>       
    <th>Waktu mulai</th>       
    <th>Group section</th>       
    <th>Pic Handle</th> 
    <th>Pic Group Section</th>             
    </tr> 
    <tr $color> 
     <td>$data[TICKET_ID]</td> 
     <td>$data[kategori]</td> 
     <td>$data[sub_sub_sub_kategori]</td> 
     <td>$data[description]</td> 
     <td>$data[npk]</td> 
     <td>$data[customer_name]</td> 
     <td>$data[position]</td> 
     <td>$data[branch]</td> 
     <td>$data[start_IT]</td> 
     <td>$data[group_section]</td> 
     <td>$data[pic_handle]</td> 
     <td>$data[pic_group_section]</td> 
    </tr>"; 
} 
$body .= "</table>"; 
$mail->Body = $body; 
$mail->send(); 
+0

Ich versuche es aber jetzt wurde meine E-Mail nicht gesendet – pahlevi

+0

E-Mail muss kommen. Es gibt nur den $ mail-> Körperteil, der sich ändert. Ruhe alles ist gleich. –

+0

Fügen Sie komplette $ mail-> Body-Teil nach $ mail-> Betreff –

0

Ein paar Dinge in den Kommentaren sind korrekt, aber Sie erstellen auch ein neues Mail-Objekt innerhalb der Schleife. Dies führt dazu, dass eine einzige E-Mail (die letzte) gesendet wird. Das ist Ihre Struktur:

while(...) { 
    // create a new object 
    $obj = new Object(); 
    ... do stuff to $obj 
    ... repeat, but never use $obj 
} 

// Guessing, now is where you do stuff with $obj, 
// but this will be the last $obj created 
$obj->send(); 

ich zwei Lösungen zu sehen, erstellen, ändern und jedes Objekt in der Schleife verwenden:

while(...) { 
    // create a new object 
    $obj = new Object(); 
    ... do stuff to $obj 
    $obj->send(); 
} 

Oder ein einzelnes Objekt erstellen, ändern und darauf aufbauen, dann die einzelnes Objekt

// create a single object outside the loop 
$obj = new Object(); 
while(...) { 
    ... do stuff to $obj 
} 
// Send the single object 
$obj->send(); 
Verwandte Themen