我有一些编程问题。当顾客在咖啡馆的网站上在咖啡馆订购一张桌子时,咖啡馆的老板可以进入并批准或拒绝订单。然后订购板的客户必须收到一封电子邮件,说明该电子邮件被接受或拒绝。
<?php
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
mysql_query("SET NAMES utf8");
mysql_query("SET character_set_results='utf8′");
function escapeAddr($addr) {
$check = preg_match('/(.*)<(.*)>/', $addr, $a);
if ($check) $addr = '=?UTF-8?B?'.base64_encode($a[1]).'?= <'.$a[2].'>';
return $addr;
}
function mail_utf8($to, $subject='no subject', $message='', $from='', $cc='', $bcc='') {
$to = $email;
$subject = "subject";
$message = "message" ;
$from = escapeAddr($from);
$header = 'From: '.$from.PHP_EOL
. 'Return-Path: '.$from.PHP_EOL
. 'Reply-To: '.$from.PHP_EOL
. 'MIME-Version: 1.0'.PHP_EOL
. 'Content-type: text/plain; charset=UTF-8'.PHP_EOL
. 'X-Mailer: PHP/'.phpversion().PHP_EOL
. 'Content-Transfer-Encoding: 8bit'.PHP_EOL;
if ($cc!='') $header .= 'Cc: '.escapeAddr($cc).PHP_EOL;
if ($bcc!='') $header .= 'Bcc: '.escapeAddr($bcc).PHP_EOL;
$header .= PHP_EOL;
return mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header);
}
$g_id = ( isset( $_GET['id']) && is_numeric( $_GET['id']) ? (int)$_GET['id'] : FALSE);
if( !$g_id) {
echo 'Error'; // ID not currect
}
else {
$query = mysql_query("SELECT email FROM $tbl_name WHERE id=$g_id");
$row = mysql_fetch_assoc($query);
$email = $row['email'];
if( mail_utf8($email, 'Table', 'message', 'no-reply@email.com')) {
echo 'Accepted';
}
else
{
echo 'Error';
}
}
?>
当然,所有者必须登录才能批准或拒绝订单。由于它是您按下拒绝或批准的表单,而是一个<a href
链接,因此我使用了 path accept.php?Id=
。
电子邮件必须发送到与订单匹配的电子邮件。