php
  • sql
  • email
  • 2012-01-31 30 views 0 likes 
    0

    我想補充這個表電子郵件:添加SQL結果表到郵件

    foreach ($songs as $key => $value) { 
          echo "<tr><td>" . ucfirst($key) . "</td><td>" . $value . "</td></tr>"; 
         } 
    

    但像這樣無法工作:

    $message = ' 
    <html> 
    <head> 
    </head> 
    <body> 
        <p>Hi, ' . ucfirst($name) . '<br> 
         </p> 
         <p>Heres the table</p> 
         <table class="tables">' . 
           foreach ($songs as $key => $value) { 
          echo "<tr><td>" . ucfirst($key) . "</td><td>" . $value . "</td></tr>"; 
         } 
           . ' 
         </table>  
    </body> 
    </html> 
    '; 
    

    謝謝提前! :)

    +1

    你發送正確的標題與HTML郵件? – Elen 2012-01-31 14:53:42

    回答

    5

    問題是你回聲而不是追加。

    $message = ' 
    <html> 
    <head> 
    </head> 
    <body> 
        <p>Hi, ' . ucfirst($name) . '<br> 
         </p> 
         <p>Heres the table</p> 
         <table class="tables">'; 
           foreach ($songs as $key => $value) { 
          $message .= "<tr><td>" . ucfirst($key) . "</td><td>" . $value . "</td></tr>"; 
         } 
    $message .= '</table>  
    </body> 
    </html> 
    '; 
    
    1

    爲什麼不生成表到一個變量,然後納入到這一點你的消息......

    foreach ($songs as $key => $value) { 
        $mytable .= "<tr><td>" . ucfirst($key) . "</td><td>" . $value . "</td></tr>"; 
    } 
    
    $message = "blah blah" . $mytable . "blah blah"; 
    
    +0

    我很確定+ =不是一個有效的PHP語法(儘管它在Javascript中有效)。改用'。='代替。 – 2012-01-31 14:57:43

    +0

    是的,剛纔看到了。我打字得太快了。 – 2012-01-31 14:58:20

    +0

    嘿,別擔心。一直髮生:) – 2012-01-31 14:58:40

    1

    您需要結束到$message值的分配,如:

    ... 
    <table class="tables">'; // stop here 
    

    然後做你的foreach,通過連接運算符,如附加的結果$message

    foreach ($songs as $key => $value) { 
        $message .= '<tr><td>' . ucfirst($key) . '</td><td>' . $value . '</td></tr>'; 
    } 
    

    然後繼續再次與$message字符串:

    $message = '</table>  
    </body> 
    </html>'; 
    
    相關問題