我對PHP相當陌生,正在用php在線訂購網站。使用'cc'發送確認電子郵件時遇到問題。在php中發送電子郵件?
每次處理訂單時,訂單總是發送到指定的'CC'地址,但不發送到'TO'。很可能是由於我的代碼中有錯誤。
在電子郵件確認收到,它只顯示從部分和「到」部分是空的,如下面所示:
From: [email protected]
To: *This space is empty*
CC: [email protected]
任何人的幫助能指出我要去的地方錯了嗎?我附上了下面的代碼。
//Code to retreive customer email
$query = "SELECT od_email
FROM tbl_order";
$result = mysql_query($query) or die(mysql_error());
$data = mysql_fetch_assoc($result);
//THIS IS THE EMAIL SENT TO THE CUSTOMER and the restaurant
//define the receiver of the email
$_SESSION['od_email'] = $data['od_email'];
$sendto = $_SESSION['od_email'];
//define the subject of the email
$subject = 'Order Confirmation | Ref No for Order: '. $_SESSION['orderId']; //this session function works properly
//define the message to be sent. Each line should be separated with \n
$message = 'test';
//Who the message is from
$from = "[email protected]";
$cc = "[email protected]";
//define the headers we want passed. Note that they are separated with \r\n
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from . "\r\n";
//bcc header going to the restaurant
$headers .= "cc:" . $cc . "\r\n";
//send the email
$mail_sent = @mail($sendto, $subject, $message, $headers);
unset($_SESSION['od_email']);
我需要它顯示的是:
From: **[email protected]**
To: **$_SESSION['od_email'];**
CC: **[email protected]**
預先感謝給予
您確定$ _SESSION ['od_email']有值嗎?如果你'var_dump($ _ SESSION ['od_email'])''得到了什麼? –
完成這件事情後,會發生同樣的事情。我相信它確實有價值。該字段數據庫中的每個部分都有一個有效的測試電子郵件地址。但是,我希望它在下訂單後選擇訂單客戶訂單的電子郵件地址。這就是爲什麼我假設我使用會話功能。 – JUM
我仍然不確定爲什麼要設置$ _SESSION ['od_email'],然後在最後取消設置。不過,看起來最可能的問題是$ sendto(和$ _SESSION ['od_email'])是NULL或空白。 'exit($ sendto);'在'mail()'之前應該打印它的值。此外,它看起來像你的查詢應該看起來像這樣:「SELECT od_email從tbl_order WHERE id = $ _ SESSION ['orderId']」,所以你不要選擇每一行。 –