我对 PHP 很陌生,正在尝试使用 php 在线订购网站。尝试使用“抄送”发送确认电子邮件时遇到问题。
每次处理订单时,订单总是发送到指定的“抄送”地址,但不会发送到“收件人”。很可能是由于我的代码中的错误。
在收到的电子邮件确认中,它仅显示 from 部分,而“to”部分为空,如下所示:
From: Business@business.co.uk
To: *This space is empty*
CC: orders@business.co.uk
谁能帮忙指出我哪里出错了?我附上了下面的代码。
//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 = "business@business.co.uk";
$cc = "orders@business.co.uk";
//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: **business@business.co.uk**
To: **$_SESSION['od_email'];**
CC: **orders@business.co.uk**
提前感谢您提供的任何帮助