2015-01-12 3 views
0

메일을 통해 목차를 보내고 싶습니다. 테이블은 다른 PHP 파일에 의해 생성됩니다.
코드는 다음과 같이메일 PHP/html 출력

<?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

출력 버퍼링에 대해 알아 패스를 저장 : HTTP : //web.archive.org/web/20101216035343/http : //dev-tips.com/featured/output-buffering-for-web-developers-a-beginners-guide – Ananth

+0

PHPMailer로 태그하지 마십시오. PHPMailer를 사용하지 않습니다. – Synchro

답변

0
ob_start(); 

// your table code comes here 

$content = ob_get_clean(); 

$to = "[email protected]"; 
$subject = "Hello"; 
$headers = "From: [email protected]" . "\r\n" 
mail($to, $subject, $content, $headers); 

// if you want the table printed un-comment the following 
// echo $content; 
0

가 하나 개의 변수를 가지고 모두가 해당 테이블의 포함 된 메일 메시지()와 같은 변수

<?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 = "[email protected]"; 

$subject = "Hello"; 
$headers = "From: [email protected]" . "\r\n" 
mail($to, $subject, $message, $headers);