你好我嘗試了一些自制的PHP腳本只是爲了瞭解PHP編碼。我創建了一個簡單的訂單系統。現在我創建一個提交按鈕來獲取我的郵箱中的php表單(由php自動創建的內容)。PHP郵件功能發送php創建的表格(表格)
這是在表中創建我的數據的腳本:
<?php //view users.php
// connect to the database
require_once 'script/login.php';
$query = "SELECT CONCAT(first_name) AS name, last_name, sex FROM users";
$result = @mysql_query ($query);
$sql = "SELECT last_name, sex, COUNT(*) AS aantal
FROM users
GROUP BY last_name, sex
ORDER BY aantal DESC";
$res = mysql_query($sql);
if($res===false) die($sql .' doet '. mysql_error());
if ($result) { //If it ran ok display the records
echo '<table align="center" cellpadding="5" cellspacing="5">
<tr><td align="left"><b>Broodje</b></td><td align="left"><b>Beleg</b></td><td align="left"><b>Hoeveelheid</b></td></tr>';
while($row=mysql_fetch_assoc($res)) {
echo '<tr><td align="left">' . $row['last_name'] . '</td><td align="left">' . $row['sex'] . '</td><td align="left">' . $row['aantal'];
}
$data = mysql_query("select count(1) as aantal from users");
$aantal = mysql_result($data, 0, 'aantal');
echo '<tr><td align="left"><strong>Totaal bestelling:</strong><td align="left"><td align="left">'.$aantal;
echo '</table>';
mysql_free_result ($result);
} else { //if it did not run ok
echo '<p class="error">The current users could not be retrieved. We apologise for any inconvienience.</p>'; //public message
echo '<p>' . mysql_error() . '<br/><br/> Query: ' . $query . '</p>'; //debugging message
}
mysql_close(); // Close database connection
?>
這個腳本工作正常。但我想通過電子郵件發送。要發送的電子郵件,我使用這個腳本:
<?php
$to = 'adress';
$subject = 'Broodje bestelling';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Put your HTML here
$message = file_get_contents('view_users.php');
// Mail it
mail($to, $subject, $message, $headers);
?>
我收到郵件,但我的消息是空的,所以我如何得到表中我的信息?
感謝您的轉發。
mysql_ *函數已被棄用.. – Tredged