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

wdebmtf2  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(360)

我想用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;
}
km0tfn4u

km0tfn4u1#

我认为这更符合您的要求(我不打算重复有关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;

相关问题