邮件PHP/html输出

邮件PHP/html输出,php,phpmailer,Php,Phpmailer,我想通过邮件发送目录。该表由另一个php文件生成 代码如下: <?php //include database configuration include 'connectdb.php'; //selecting records $sql='select i.id, i.description, u.firstname, i.created_on, u1.firstname, i.closed_on, i.id AS id, i.description AS de

我想通过邮件发送目录。该表由另一个php文件生成
代码如下:

<?php

//include database configuration

include 'connectdb.php';

//selecting records

$sql='select i.id, i.description, u.firstname, i.created_on, u1.firstname, i.closed_on, 
    i.id AS id,
    i.description AS description,
    u.firstname AS firstname,
    i.created_on AS created_on,
    u1.firstname AS u1_firstname,
    i.closed_on AS closed_on
    from issues AS i
    INNER JOIN users AS u ON i.author_id = u.id
    INNER JOIN users AS u1 ON i.assigned_to_id = u1.id';  
//query the database

$rs=mysqli_query($conn,$sql) or die($sql.">>".mysqli_error($conn));

//count how many records found

$num=mysqli_num_rows($rs);



if($num>0){ //check if more than 0 record found

    ?>

    <table border='1'>

    <tr>

    <th>Issue ID</th>

    <th>Description</th>

    <th>Raised by</th>

    <th>Raised on</th>

    <th>Assigned to</th>

    <th>Current State</th>

    </tr>

    <?php
    echo $num;
    //retrieve our table contents

    while($row=mysqli_fetch_array($rs)){

        //extract row

        //this will make $row['firstname'] to

        //just $firstname only

        extract($row);
        if($closed_on === null){
        //refering to other tables 
        //$dateob=substr($DOB,8,2).'-'.substr($DOB,5,2).'-'.substr($DOB,0,4);
        ?>

        <tr>

        <td><?php echo $id; ?></td>

        <td><?php echo $description; ?></td>

        <td><?php echo $firstname; ?></td>

        <td><?php echo $created_on; ?></td>

        <td><?php echo $u1_firstname; ?></td>

        <td><?php 

                echo 'Open Ticket';

            ?></td>

        </tr>

        <?php
        }
    }

}
else{ //if no records found

    echo "No records found.";

}

?>
</table>

问题ID
描述
抚养
抚养
分配给
现状

取一个变量并存储该表的所有内容 将该变量作为邮件()中的消息传递


了解输出缓冲:如果不使用PHPMailer,请不要标记为PHPMailer。
ob_start();

// your table code comes here

$content = ob_get_clean();

$to = "toemail@domain.com";
$subject = "Hello";
$headers = "From: fromemail@domain.com" . "\r\n"
mail($to, $subject, $content, $headers);

// if you want the table printed un-comment the following
// echo $content;
<?php

//include database configuration

 include 'connectdb.php';

 //selecting records

    $sql='select i.id, i.description, u.firstname, i.created_on, u1.firstname, i.closed_on, 
i.id AS id,
i.description AS description,
u.firstname AS firstname,
i.created_on AS created_on,
u1.firstname AS u1_firstname,
i.closed_on AS closed_on
from issues AS i
INNER JOIN users AS u ON i.author_id = u.id
INNER JOIN users AS u1 ON i.assigned_to_id = u1.id';  
//query the database

$rs=mysqli_query($conn,$sql) or die($sql.">>".mysqli_error($conn));

//count how many records found

 $num=mysqli_num_rows($rs);
 $message = '';


  if($num>0){ //check if more than 0 record found



$message .= "<table border='1'>";

$message .= "<tr>";

$message .= "<th>Issue ID</th>"

$message .= "<th>Description</th>";

$message .= "<th>Raised by</th>";

$message .= "<th>Raised on</th>";

$message .= "<th>Assigned to</th>";

$message .= "<th>Current State</th>";

$message .= "</tr>";
echo $num;
//retrieve our table contents

while($row=mysqli_fetch_array($rs)){

    //extract row

    //this will make $row['firstname'] to

    //just $firstname only

    extract($row);
    if($closed_on === null){
    //refering to other tables 
    //$dateob=substr($DOB,8,2).'-'.substr($DOB,5,2).'-'.substr($DOB,0,4);


    $message .=" <tr>";

    $message .= "<td>". $id."</td>";

    $message = "<td>". $description."</td>";

    $message .= "<td>".$firstname."</td>";

    $message .= "<td>". $created_on."</td>";

    $message .= "<td>". $u1_firstname."</td>";

    $message .= "<td>";

            echo 'Open Ticket';

     $message .= "</td>";

    $message .= "</tr>";


    }
  }

 }
 else{ //if no records found

echo "No records found.";
}

 $message .= "</table>";

 $to = "toemail@domain.com";

 $subject = "Hello";
 $headers = "From: fromemail@domain.com" . "\r\n"
 mail($to, $subject, $message, $headers);