2016-02-05 28 views
0

我有一個關於通過php發送電子郵件的一般性問題。你如何將PHP數組放入郵件的消息部分?如何在電子郵件中添加一個php數組?

下面你可以看到一個簡單的數組,我做了,並試圖把它放在電子郵件中,但這是完全錯誤的,因爲我沒有找到它在互聯網上如何做到這一點(我是一個初學者。 PHP)。

數組:

<?php 
    $Array[1] = array('qualitypoint', 'technologies', 'India','Hey'); 
    $Array[2] = array('quality', 'tech', 'Ind','He'); 
    $Array[3] = array('q', 't', 'I','H'); 
    ?> 

的郵件:

<?php 
    include "index.php"; 
    while($row = $LevAdres->fetch_assoc()) { 
     $email=null; 
     $email= $row['Email']; 
    } 

    $to = [email protected]; 


    $subject = "Bestelling"; 


    $headers = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
    $headers .= "From: [email protected]" . "\r\n"; 
    $headers .= "Reply-To: [email protected]". "\r\n"; 
    $headers .= "CC: [email protected]\r\n";   

    $message = "<?php 

    echo '<table>'; 
    echo '<table>'; 
    for($i=0;$i<=3;$i++) 
    { 
     echo "<tr>"; 
     for($j=1;$j<=3;$j++) 
     {  
     echo "<td>{$Array[$j][$i]}<td>"; 
     } 
     echo "</tr>";  
    } 
    echo '</table>'; 
    ?>"; 


    if (mail($to, $subject, $message, $headers)) { 
    echo '<p>successfully sent.</p>'; 
    } else { 
    echo'<p>delivery failed...</p>'; 
    } 


    ?> 

This is how the table must look like

回答

0

在這裏你去......完整的代碼

 $Array[1] = array('qualitypoint', 'technologies', 'India', 'Hey'); 
     $Array[2] = array('quality', 'tech', 'Ind', 'He'); 
     $Array[3] = array('q', 't', 'I', 'H'); 

     $to = "[email protected]"; 

     $subject = "Bestelling"; 

     $headers = "MIME-Version: 1.0\r\n"; 
     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
     $headers .= "From: [email protected]" . "\r\n"; 
     $headers .= "Reply-To: [email protected]" . "\r\n"; 
     $headers .= "CC: [email protected]\r\n"; 

     $message = ""; 
     $message .= '<table>'; 
     for ($i = 0; $i <= 3; $i++) { 
      $message .= "<tr>"; 
      for ($j = 1; $j <= 3; $j++) { 
       $message .= "<td>{$Array[$j][$i]}</td>"; 
      } 
      $message .= "</tr>"; 
     } 
     $message .= '</table>'; 


     if (mail($to, $subject, $message, $headers)) { 
      echo '<p>successfully sent.</p>'; 
     } else { 
      echo'<p>delivery failed...</p>'; 
     } 
+0

請更改電子郵件地址添加到您的電子郵件地址,請。你不斷給我發電子郵件! @Sander Herreman –

0

您的$消息變量更改了這一點。

$message = "<table>"; 
for($i=0;$i<=3;$i++) 
    { 
     $message .= "<tr>"; 
     for($j=1;$j<=3;$j++) 
     {  
     $message .= "<td>{$Array[$j][$i]}<td>"; 
     } 
     $message .= "</tr>";  
    } 
    $message .= '</table>'; 
0

如果你想放入的消息,然後不迴應,但如果你想呼應它,它的回聲代碼寫在郵件正文

變化

$array = [ 
    ['qualitypoint', 'technologies', 'q'], 
    ['technologies', 'tech', 't'], 
    ['India', 'ind', 'i'], 
]; 

$message = ""; 
$message .= '<table>'; 
foreach ($array as $row) 
{ 
    $message .= "<tr>"; 
    foreach ($row as $cell) 
    {  
     $message .= "<td>$cell</td>"; 
    } 
    $message .= "</tr>";  
} 
$message .= '</table>'; 

然而那麼你可以捕獲輸出緩衝並使用它的內容,但我不推薦它。使用foreach使其更具可讀性。另外考慮用較低的駱駝情況命名你的變量。

0

我可以看到你有雙引號問題。試試這樣: echo '<td>'."{$Array[$j][$i]}".'<td>';

相關問題