以PHP发送确认电子邮件
我对PHP相当陌生,并且正在用PHP在线订购网站进行实验。使用'cc'发送确认电子邮件时遇到问题。以PHP发送确认电子邮件
每次处理订单时,订单总是发送到指定为'$ from'的'CC'地址,发件人(发件人)是'$ to'部分中指定的地址。在收到确认电子邮件,它只显示从部分和“对”和“CC”是空的,如下面所示:
From: **$_SESSION['od_email']** To: *This space is empty*
CC: [email protected]
谁能帮助指出我要去的地方错了吗?我附上了下面的代码。
//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 = "[email protected]";
$cc = "[email protected]";
//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: **[email protected]** To: **$_SESSION['od_email'];**
CC: **[email protected]**
预先感谢给予
回答:
当你要设定的CC任何帮助,你覆盖是什么在$标头中。尝试:
$headers = "From:" . $from . "\r\n"; $headers.= "Cc:" . $cc;
如果这没有帮助,总是有关于mail
的PHP文档。
回答:
我会全力以赴配合你的头,并确保你设置你需要的一切,
// 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";
还,我相信邮件()需要一个有效的电子邮件地址,我不知道你怎么有在$_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 = "[email protected]";
$cc = "[email protected]";
// 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);
更换任何变量。
总是为我工作。
以上是 以PHP发送确认电子邮件 的全部内容, 来源链接: utcz.com/qa/260062.html