我有一个动态表单,它收集移动数据并通过php代码发送到电子邮件。 。 PHP代码如下所示。
<?php
if(!isset($_POST['submit']))
{
//Need to submit the form.
exit;
}
$sl = $_POST['sl'];
$name = $_POST['name'];
$place= $_POST['place'];
$mob = $_POST['mob'];
$email_body =
"NAME PLACE MOBILE \n".
“===========================\n\n”;
$email_body .=
for ($i = 0; $i < count($sl); $i++) {
$i= $i+1;
"(" . $sl[$i] . ") " . $name[$i] . " " . $place . “ “ . $mob . “ “ ;\n";
}
$email_from = 'xxxt@xyz.com';
$email_subject = "Phone details";
$to = "yyy@xyz.com";
$headers = "From: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
以上代码以下列方式发送移动详细信息:
SL NAME PLACE MOBILE
(1)Jhon Newyork 6765464564
(2)Robert steevejobs wshinton 6767565
(3)Madam levies satllen forthe Canada 454645
我需要以下列格式的邮件。
SL NAME PLACE MOBILE
(1) Jhon Newyork 6765464564
(2) Robert steevejobs wshinton 6767565
(3) Madam levies satllen forthe Canada 454645
请问有谁能帮助我吗?
答案 0 :(得分:1)
您可以在电子邮件正文中显示html表格:
$body = '<table>';
$body .= '<thead><th>Column 1 title</th><th>Column 2 title</th></thead>';
$body .= '<tbody>';
$body .= '<tr><td>Col 1</td><td>Col 2</tr>';
$body .= '</tbody>';
$body .= '</table>';
并且不要忘记在标题中指定要显示html:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
答案 1 :(得分:0)
使用<table>
$email_body = "<table>";
$email_body .= "<tr>";
$email_body .= "<td>SL</td>";
$email_body .= "<td>NAME</td>";
$email_body .= "<td>PLACE</td>";
$email_body .= "<td>MOBILE</td>";
$email_body .= "</tr>";
for ($i = 0; $i < count($sl); $i++) {
$i= $i+1;
$email_body .= "<tr>";
$email_body .= "<td>(" . $sl[$i] . ")</td> ";
$email_body .= "<td>". $name[$i] . "</td>";
$email_body .= "<td>". $place . "</td>";
$email_body .= "<td>". $mob . "</td>";
$email_body .= "</tr>";
}
$email_body .= "</table>";
答案 2 :(得分:0)
$email_body = '<table>';
$email_body .= '<thead><th>SL</th><th>NAME</th><th>PLACE</th><th>MOBILE</th></thead>';
$email_body .= '<tbody>';
$email_body .= '<tr><td>Col 1</td><td>Col 2</td><td>Col 3</td><td>Col 4</td></tr>';
$email_body .= '</tbody>';
$email_body .= '</table>';
add header also -
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";