2011-12-28 11 views
1

これは1ページでうまくいきます。それは私に必要なすべての情報を提供します。しかし、私はそれを電子メールを送信したい。私はそれをDBから情報を引き抜いた後の方法

$db = new mysqli('localhost', 'root', '', 'panel'); 
$sql = "select * from detail"; 
$read = $db->query($sql); 

<table style="border:0;width:600px;"> 
    <tr> 
    <td width="50px">Who</td> 
    <td width="150px">Time</td> 
    <td width="300px">What</td> 
    </tr> 
<?php 
while($wr = mysqli_fetch_array($read)) { 
echo' <tr> 
    <td>'.$wr['Who'].'</td> 
    <td>'.$wr['Time'].'</td> 
    <td>'.$wr['What'].'</td> 
    </tr> '; 
} 


?> 
+0

送信しようとしているデータは何ですか? – Sedz

+0

[メール()](http://php.net/mail)の機能を見てみてください... – Tyil

答えて

0

を行うことができますあなたは(ブラウザに送信しないことを意味はなく、これをバッファに蓄積する)あなたが作成しているHTMLのすべてをバッファリングして送信する必要がある方法を見つけ出すcouldn`tが、このような電子メールとしてユーザーにバッファリングします。

// Start buffering 
ob_start(); 
// Generate HTML just like you're doing now 
echo("<html><body><table><tr><td></td></tr></table></body></html>"); 
// Get the contents of the buffer 
$html = ob_get_contents(); 
// Stop the buffering 
ob_end_clean(); 

// Now use the content string you have to send an email just like the example at: 
// http://il.php.net/manual/en/function.mail.php 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'To: [email protected]' . "\r\n"; 
$headers .= 'From: [email protected]' . "\r\n"; 

mail("[email protected]", "This is the subject", $html, $headers); 
+1

私は本当に何をする必要があるのか​​理解できませんでしたが、私はショットを与えます – Extelliqent

+0

あなたが正しく理解していれば、生成されたHTMLを電子メールとして送信したいと思うでしょう。その場合、自分のスクリプトが行うのは、あなたが通常と同じ方法でHTMLを "送る"ことです。しかし、 (PHPで扱われる)バッファに蓄積され、後で 'ob_get_contents()'を使って収集することができます。最終結果は、ブラウザに送信されるはずのHTMLで構成される文字列です。 – Yaniro

関連する問題