0

我需要将用户报告发送到管理员电子邮件,这里我面临的问题只有一行数据发送,而数据未发送。如果我提交 2 行数据,则只有一行数据会发送到电子邮件。如果我只发送一行,它工作正常。谁能告诉我如何将两行数据发送到单个电子邮件。

<form>
<div>S.No  <input type="text" name="sno[]" /></div>
<div>Work Report  <input type="text" name="report[]" /></div>
<div>Status  <input type="text" name="status[]" /></div>
--------------------------------------------------------
<div>S.No  <input type="text" name="sno[]" /></div>
<div>Work Report  <input type="text" name="report[]" /></div>
<div>Status  <input type="text" name="status[]" /></div>
<input type="submit" name="Submit" />
</form>

代码是

<?php
$sno = $_POST['sno'];
$report = $_POST['report'];
$status = $_POST['status'];
foreach($sno as $v => $i)
{
$sno[$v];
$report[$v];
$status[$v];
$html = "
<html>
<head>
<style>
table.fancy_table tbody td              
{
font-family:'Calibri';
font-size:15px; line-height:18px; color:#333; background-color:#fff;
word-wrap: break-word;
}
table.fancy_table       {border: 0px solid #dddddd; }
table.fancy_table th    {border: 0px solid #dddddd;  padding:4px; color:#993300; text-transform:uppercase; background-color:#FFFFFF; }
table.fancy_table td    {border: 1px solid #dddddd; background:#ffffff; padding:4px; text-align:left; , height:30px; }
table.fancy_table tbody td   { background:#FFFFFF;}           
table.fancy_table {border-collapse: collapse; border-spacing: 0; width:450px; margin:0 auto; margin-bottom:15px; }
</style>    

</head>
<body>
<table class='fancy_table'>
<tr>
<td span style='color:#993300'><strong>S.NO</span></td>
<td span style='color:#993300'><strong>Report</span></strong></td>
<td span style='color:#993300'><strong>STATUS</span></strong></td>
</tr>
<tr>
<td width='50'>$sno[$v]</td>
<td width='150'>$report[$v]</td>
<td width='130'>$status[$v]</td>
</tr>
</table>
</body>
</html> 
";  
}//endforeach

$crlf = "\n";
$mime = new Mail_mime;
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail = $smtp->send($recipients, $headers, $body);


$errmsg_arr[] =  'Mail Successfully Sent';
$errflag = true;
}
else
{
$errmsg_arr[] = 'Mail Not Sent';
$errflag = true;
}




?> 
4

1 回答 1

0

将数据放入 foreach 循环中:

  <?php
$sno = $_POST['sno'];
$report = $_POST['report'];
$status = $_POST['status'];

$html = "
<html>
<head>
<style>
table.fancy_table tbody td              
{
font-family:'Calibri';
font-size:15px; line-height:18px; color:#333; background-color:#fff;
word-wrap: break-word;
}
table.fancy_table       {border: 0px solid #dddddd; }
table.fancy_table th    {border: 0px solid #dddddd;  padding:4px; color:#993300; text-transform:uppercase; background-color:#FFFFFF; }
table.fancy_table td    {border: 1px solid #dddddd; background:#ffffff; padding:4px; text-align:left; , height:30px; }
table.fancy_table tbody td   { background:#FFFFFF;}           
table.fancy_table {border-collapse: collapse; border-spacing: 0; width:450px; margin:0 auto; margin-bottom:15px; }
</style>    

</head>
<body>
<table class='fancy_table'>
<tr>
<td span style='color:#993300'><strong>S.NO</span></td>
<td span style='color:#993300'><strong>Report</span></strong></td>
<td span style='color:#993300'><strong>STATUS</span></strong></td>
</tr>";
foreach($sno as $v => $i)
{
$sno[$v];
$report[$v];
$status[$v];
$html.="<tr><td width='50'>$sno[$v]</td><td width='150'>$report[$v]</td><td width='130'>$status[$v]</td></tr>";
}//endforeach
$html.="</table></body></html>";  


$crlf = "\n";
$mime = new Mail_mime;
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail = $smtp->send($recipients, $headers, $body);


$errmsg_arr[] =  'Mail Successfully Sent';
$errflag = true;
}


?>

用这个替换你的完整代码。艾哈迈尔。

于 2013-08-17T06:29:36.607 回答