gpt4 book ai didi

php - 如何在 php 中发送电子邮件正文中的 html 表?

转载 作者:太空狗 更新时间:2023-10-29 15:27:42 25 4
gpt4 key购买 nike

我在电子邮件正文中发送动态创建的 html 表格,但在电子邮件中我收到 html 代码而不是显示表格。请帮我。这是我的代码。

<?php
$output = '<html><body><form>';

$output .= '<table border="1"><tr><th>Author</th><th>Node Title</th><th>Node Summary</th><th>Node Body</th><th>Edit this node</th><th>Report Abuse</th><th>Group</th></tr>';
while($row = mysql_fetch_array($sql)) {



$data = explode('"', $query['data']);
$output .= '<tr><td>';

if($row['created'] >= $strdate && $row['created'] < $enddate) {

$output .= '<a href="http://localhost/localstage/user/' . $row['uid'] . '">' . $query['name'] . '</a></td><td>';
$output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '">' . $row['title'] . '</a> (New)</td><td>';
}
else {

$output .= '<a href="http://localhost/localstage/user/' . $sql_query['uid'] . '">' . $query['name'] . '</a></td><td>';
$output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '">' . $row['title'] . '</a> (Updated)</td><td>';
}
//$output .= '</td><td>';
$output .= $row['teaser'] . '</td><td>';
if($row['field_provcomp_level_value'] == 0 || $row['field_provcomp_level_value'] == 1)<br /> {
$output .= $row['body'] . '</td><td>';
}
else {
$output .= '</td><td>';
}
$output .= '<a href="http://localhost/localstage/abuse/report/node/' . $row['nid'] . '">Abuse</a></td><td>';
$output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '/edit">Edit</a></td><td>';
$query = mysql_fetch_array(mysql_query("SELECT title from node Where type = 'groupnode' AND nid = '" . $row['nid'] . "'"));
$output .= $query['title'] . '</td></tr>';
}

$output .= '</table></form></body></html>';
print $output;
$to = 'hmdnawaz@gmail.com';
$headers = "From Ahmad \r\n";
//$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
//$headers .= "CC: susan@example.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$subject = 'Email report';
mail($to, $subject, $output, $headers);
if(mail) {
echo 'Email sent';
}
else {
echo 'Error sending email';
}
?>

最佳答案

首先,您在 HTML 代码中缺少标记,但这应该不是问题。

其次,您的 header 不正确,您有:

$headers = "From Ahmad \r\n";
//$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
//$headers .= "CC: susan@example.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$subject = 'Email report';

代替:

//$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
//$headers .= "CC: susan@example.com\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= "From: Ahmad <email@email.com>\r\n";
$subject = 'Email report';

基本上我认为你的标题应该以“Mime-Version”开头。

检查此代码:http://us.php.net/manual/en/function.mail.php#example-2877

关于php - 如何在 php 中发送电子邮件正文中的 html 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6160320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com