我对PHP很陌生,正在尝试用php进行在线订购网站。我在尝试使用"抄送"发送确认电子邮件时遇到了问题。
每次处理订单时,订单始终发送到指定为"$from"的"抄送"地址,发件人(发件人)是"$to"部分中指定的地址。在收到的电子邮件确认中,它仅显示发件人部分,并且"收件人"和"抄送"为空,如下所示:
From: **$_SESSION['od_email']**
To: *This space is empty*
CC: orders@business.co.uk
谁能帮忙指出我哪里出了问题?我附上了下面的代码。
//THIS IS CODE FOR THE EMAIL WHICH IS AUTOMATICALLY SENT TO THE CUSTOMER AND THE BUSINESS WHEN AN ORDER IS SUCCESSFULLY COMPLETED
//define the receiver of the email
$to = $_SESSION['od_email'];
//define the subject of the email
$subject = 'Order Confirmation | Ref No for Order: '. $_SESSION['orderId'];
//define the message to be sent. Each line should be separated with 'n
$message = 'test';
//Who the message is from
$from = "orders@business.co.uk";
$cc = "orders@business.co.uk";
//define the headers we want passed. Note that they are separated with 'r'n
$headers = "From:" . $from;
//bcc header going to the to go to the business as confirmation
$headers = "cc:" . $cc;
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
我需要显示的是:
From: **orders@business.co.uk**
To: **$_SESSION['od_email'];**
CC: **orders@business.co.uk**
提前感谢您提供的任何帮助
当您要设置 CC 时,您将覆盖$headers中的内容。 尝试:
$headers = "From:" . $from . "'r'n";
$headers.= "Cc:" . $cc;
如果这没有帮助,那么总是有 PHP 的文档关于 mail
.
我会全力以赴使用您的标题,并确保您设置了所需的一切,
// 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: ' .$to. "'r'n";
$headers .= 'From: ' .$from. "'r'n";
$headers .= 'Cc: '.$cc. "'r'n";
另外,我相信 mail() 需要一个有效的电子邮件地址,我不知道您如何在$_SESSION['od_email']
之前设置电子邮件,但是如果您正在运行测试并且实际上期望$_SESSION['od_email']
附带它不起作用,它会将其视为无效的电子邮件并返回 false,因此什么也不返回。 为了进一步诊断该问题,我们需要知道$_SESSION['od_email']
是如何设置
编辑
好的,我很确定问题是由您如何根据下面的评论设置$_SESSION['od_email]'
引起的。
注意:我假设您的数据库是$db
的,但如果不是,您需要将$db
更改为探测器名称
让我们试试这个,看看它是如何工作的
// Get Data from the Database
$query = "SELECT `od_email` FROM `tbl_order`";
$result = $db->query($query);
while ($data = $db->fetch_array($result)) {
// Set Up the SESSION email
$_SESSION['od_email'] = $data['od_email'];
// Prepare the Email
$to = $_SESSION['od_email'];
$subject = 'Order Confirmation | Ref No for Order: '. $_SESSION['orderId'];
$message = 'test';
$from = "orders@business.co.uk";
$cc = "orders@business.co.uk";
// 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: ' .$to. "'r'n";
$headers .= 'From: ' .$from. "'r'n";
$headers .= 'Cc: '.$cc. "'r'n";
// Send the email
mail($to,$subject,$message,$headers);
}
他不能加一个@mail吗? 如...
$mail_sent = @mail( $od_email, $subject, $message, $headers );
或
mail( $od_email, $subject, $message, $headers );
替换任何变量。
一直为我工作。