1

我一直在使用这个邮件程序,但现在我需要添加(多个)永久密件抄送地址。我怎样才能做到这一点?

到目前为止,这是我的代码:

<?php

$message = '';

if (isset($_POST['email']) && !empty($_POST['email'])) {
    if (mail($_POST['email'], $_POST['subject'], $_POST['body'], "From: me@mydomain")) {
        $message = "Email has been sent to <b>".$_POST['email']."</b>.<br>";
    } else {
        $message = "Failed sending message to <b>".$_POST['email']."</b>.<br>";
    }
} else {
    if (isset($_POST['submit'])) { 
        $message = "No email address specified!<br>";
    }
} 

if (!empty($message)) {
    $message .= "<br><br>";
}

?>
4

3 回答 3

2

试试这个它可能对你有用:

<?php
$msgTo = "msgTo@email.com";
$msgSubject = "Mail Subject";
$msgContent = "This is the message,:)";

$bcc = "msgbcc@email.com";

$msgHeaders = "To: $msgTo\r\n";
$msgHeaders .= "From: no-reply@email.com\r\n";
$msgHeaders .= "Bcc: $bcc\r\n";
$msgHeaders .= "X-Mailer: PHP".phpversion();

$success = mail($msgTo, $msgSubject, $msgContent, $msgHeaders);?>
于 2013-08-27T10:00:25.410 回答
2

尝试这个:

<?php
    $thirdMail = "three@example.com\r\n";
    $header = "From: email@example.com\r\n";
    $header .= "BCC: one@example.com,two@example.com,".$thirdMail;
    mail($toMail, $subject, $message, $header);
?>

如您所见,每个地址都用逗号分隔。

于 2013-08-27T09:37:41.703 回答
2

请参阅此处,这将提供有助于在 mail() 中设置 cc 和 bcc 的详细信息。

例如,

$bcc = array_of_bcc_users;
$headers = 'From: admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $bcc) . "\r\n";

mail($to, $title, $content, $headers);
于 2013-08-27T09:40:37.983 回答