PHP 电子邮件:收件人、抄送

发布于 2024-10-26 18:03:23 字数 764 浏览 4 评论 0原文

我有一个可以自动发送电子邮件的 PHP 脚本。我的它工作得很好,但是当我尝试添加 CC 时,它不起作用。以下是我的电子邮件代码:

$email_to = "$theData2"; // Who the email is to 

$headers = "From: ".$email_from; 

$ok = @mail($email_to, $email_subject, $email_message, $headers);

我已经尝试了以下方法来使 CC 正常工作,但没有任何运气。

$email_cc = "[email protected]"; 
$headers .= "CC: ".$email_cc;

并且也尝试过这个:

$headers .= "CC: [email protected]";

我无法将其通过电子邮件发送到:to &抄送。

任何帮助将不胜感激。谢谢!

I have a PHP script that automatically send outs an email. I have it working great, but when I try to add a CC, it doesn't work. Below is my code for the email to:

$email_to = "$theData2"; // Who the email is to 

$headers = "From: ".$email_from; 

$ok = @mail($email_to, $email_subject, $email_message, $headers);

I have tried the following to get CC to work, but I haven't had any luck.

$email_cc = "[email protected]"; 
$headers .= "CC: ".$email_cc;

and also have tried this:

$headers .= "CC: [email protected]";

I can't get it to email to both the: to & cc.

Any help would be greatly appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

£冰雨忧蓝° 2024-11-02 18:03:24

您是否尝试过使用“抄送”而不是“抄送”?并且不要忘记末尾的“\n”。

Have you tried with "Cc" and not "CC" ? And do not forget the "\n" at the end.

情痴 2024-11-02 18:03:24

不要直接使用 PHP 的 mail() 函数。使用包装类,例如 SwiftMailerPHPMailer。它们为您提供更大的灵活性并且更安全。

Don't use PHPs mail() function directly. Use a wrapper class such as SwiftMailer or PHPMailer. They give you far more flexibility and are safer.

灰色世界里的红玫瑰 2024-11-02 18:03:23

您忘记了换行符。

$headers .= "\r\nCc: ".$email_cc;

You forgot your newline.

$headers .= "\r\nCc: ".$email_cc;
心安伴我暖 2024-11-02 18:03:23

尝试以 "\r\n" 结束标头条目:

$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

Try ending your header entries with "\r\n":

$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文