gpt4 book ai didi

php - 用 PHP 发送确认电子邮件

转载 作者:行者123 更新时间:2023-12-04 15:52:46 26 4
gpt4 key购买 nike

我对 PHP 很陌生,正在尝试使用 php 构建在线订购网站。我在尝试使用“抄送”发送确认电子邮件时遇到问题。

每次处理订单时,订单始终发送到指定为“$from”的“CC”地址,而发件人(发件人)是“$to”部分中指定的地址。在收到的电子邮件确认中,仅显示发件人部分,“收件人”和“抄送”为空,如下所示:

From: **$_SESSION['od_email']**
To: *This space is empty*
CC: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5baa7b1b0a7a695b7a0a6bcbbb0a6a6fbb6bafba0be" rel="noreferrer noopener nofollow">[email protected]</a>

谁能帮忙指出我哪里出错了?我附上了下面的代码。

//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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f706d7b7a6d6c5f7d6a6c76717a6c6c317c70316a74" rel="noreferrer noopener nofollow">[email protected]</a>";
$cc = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="78170a1c1d0a0b381a0d0b11161d0b0b561b17560d13" rel="noreferrer noopener nofollow">[email protected]</a>";
//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: **<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="58372a3c3d2a2b183a2d2b31363d2b2b763b37762d33" rel="noreferrer noopener nofollow">[email protected]</a>**
To: **$_SESSION['od_email'];**
CC: **<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b74697f7e69685b796e6872757e6868357874356e70" rel="noreferrer noopener nofollow">[email protected]</a>**

预先感谢您提供的任何帮助

最佳答案

当您要设置 CC 时,您将覆盖 $headers 中的内容。尝试:

$headers = "From:" . $from . "\r\n";
$headers.= "Cc:" . $cc;

如果这没有帮助,总有关于 mail 的 PHP 文档.

关于php - 用 PHP 发送确认电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10973406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com