邮件PHP / html输出

时间:2015-01-12 10:07:45

标签: 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 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>

1 个答案:

答案 0 :(得分:0)

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;