将多行发送到一封电子邮件,但发送多行电子邮件

时间:2018-01-04 06:09:07

标签: php mysql html5

我想在php中发送包含多行数据库的电子邮件,但是当我发送电子邮件的时候发送多行电子邮件时会有单行数据,但我想要一行包含多行电子邮件。

我不知道我哪里错了。下面是我在php和mysql中运行的代码。

$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");

for ($i = 0; $i < count($fm_id); $i++)
{
    $update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
    $res=mysql_query($update);

    $update1=("UPDATE fm_status SET  date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
    $res1=mysql_query($update1);

    $to ='abc@gmail.com'. ', ';
    $to .='abc@abc.com';

    $subject="Ticket Details from ";
    $header="Solution ";

    $header  = 'MIME-Version: 1.0' . "\r\n";
    $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $header .= 'From: FM Engineer<solution@abc.com>' . "\r\n" ;

    $message = '<html><body>';
    $message .= '<head>';
    $message .= '</head>';

    $message .= "    <align=center>  <div id='apDiv2'>
        <table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
         <thead>
            <tr>

                <th><h3> Raised By </h3></th>

                <th><h3> Issue </h3></th>
                <th><h3> Resolution </h3></th>
                <th><h3> Status </h3></th>

                </tr> </thead>
        <tbody>

        <td> ".$issue[$i]."</td>             
        <td> ".$issue[$i]."</td>
        <td> ".$resolution[$i]."</td>
        <td> ".$issue[$i]."</td>

        </tr><tbody></table>";

                $message .= '<br>';

    $message .= "</body></html>";

    $sentmail = mail($to,$subject,$message,$header);


    echo $sentmail;
}

1 个答案:

答案 0 :(得分:0)

我认为这更符合您的要求(我不会重申有关mysql_ *函数的警告)。如果您尝试向表中添加行以发送一封电子邮件,那么只需使用for循环构建行:

$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");

$to ='abc@gmail.com'. ', ';
$to .='abc@abc.com';

$subject="Ticket Details from ";
$header="Solution ";

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: FM Engineer<solution@abc.com>' . "\r\n" ;

$message = '<html>';
$message .= '<head>';
$message .= '</head><body>';
$message .= "    <align=center>  <div id='apDiv2'>
    <table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
     <thead>
        <tr>

            <th><h3> Raised By </h3></th>

            <th><h3> Issue </h3></th>
            <th><h3> Resolution </h3></th>
            <th><h3> Status </h3></th>

            </tr> </thead>
    <tbody>";


for ($i = 0; $i < count($fm_id); $i++)
{
  $update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
  $res=mysql_query($update);

  $update1=("UPDATE fm_status SET  date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
  $res1=mysql_query($update1);

  $message .= "<tr>
          <td> ".$issue[$i]."</td>             
          <td> ".$issue[$i]."</td>
          <td> ".$resolution[$i]."</td>
          <td> ".$issue[$i]."</td>

          </tr>";
}

    $message .= '<tbody></table><br>';

    $message .= "</body></html>";

    $sentmail = mail($to,$subject,$message,$header);

    echo $sentmail;