以下代码部分功能。我认为,问题领域在查询部分附近。在tbody之后,如果我包含连接句点(。)代码可以工作,除了查询本身成为消息的一部分。
如果我删除它,我会收到一个解析错误(解析错误:语法错误,意外' $ sql'(T_VARIABLE))。我被卡住了。
以下是包含连接的结果:
客户列表
报告要求:吉姆
ID名称地址城市州邮编电话联系电子邮件
SELECT * FROM客户ORDER BY名称
1 Duke and Duke 5555 Rockefeller Plaza纽约NY 10055 212-555-1212 Mortimer Duke Randolph.Duke@Duke.com
感谢任何帮助!
//*********************** Email client list ***********************//
if(isset($_POST['action']) && $_POST['action'] === 'email client list')
{
include '../includes/dbconnect-local.php';
/******** Prepare to mail *********/
// Recipients
$jim = 'jim@gmail.com';
$to = $jim;
$from = 'Administrator@company.com';
// Subject
$subject = 'Client List';
// Message
$message = '
<html>
<body>
<h2>Client List</h2>
<h3>Report requested by: ' . $_SESSION['name'] . '</h3>
<table style="width:100%;">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Telephone</th>
<th>Contact</th>
<th>Email</th>
<tr>
</thead>
<tbody>
' .
// Get all client data
$sql = 'SELECT * FROM client ORDER BY name';
$result = $db->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
$message .= '<tr>';
$message .= '<td>' . htmlspecialchars($row['id']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['name']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['address']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['city']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['state']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['zip']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['telephone']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['contact_name']) . '</td>';
$message .= '<td>' . htmlspecialchars($row['contact_email']) . '</td>';
$message .= '<tr>';
}
$message .= '
</tbody>
</table>
</body>
</html>';
// 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";
// Additional headers
$headers .= 'To: ' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Cc: ' . "\r\n";
$headers .= 'Bcc: ' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
// Redirect
header('Location: .');
exit();
}