我有一个关于通过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 = example@hotmail.com;
$subject = "Bestelling";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: Restaurant@test.be" . "\r\n";
$headers .= "Reply-To: people@info.be". "\r\n";
$headers .= "CC: Restaurant@test.be\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>';
}
?>
答案 0 :(得分:0)
将$ 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>';
答案 1 :(得分: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也使它更具可读性。还要考虑使用较低的camel情况命名变量。
答案 2 :(得分:0)
我可以看到你有双引号问题。试试这样:
echo '<td>'."{$Array[$j][$i]}".'<td>'
;
答案 3 :(得分:0)
在这里你......完整的代码
$Array[1] = array('qualitypoint', 'technologies', 'India', 'Hey');
$Array[2] = array('quality', 'tech', 'Ind', 'He');
$Array[3] = array('q', 't', 'I', 'H');
$to = "example@hotmail.com";
$subject = "Bestelling";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: Restaurant@test.be" . "\r\n";
$headers .= "Reply-To: your@email.com" . "\r\n";
$headers .= "CC: Restaurant@test.be\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>';
}