简体   繁体   English

PHP邮件忽略密件抄送

[英]PHP mail ignores Bcc

I'm really struggling with this class. 我真的在努力学习这门课。 I'm sending a mail like this: 我发这样的邮件:

try {
    // minimal requirements to be set
    $dummy = new Mailer();
    $dummy->setFrom("MAIL SCRIPT", "info@mail.com");
    $dummy->addRecipient($naam, $email);
    $dummy->fillSubject("Jouw ruiling #" . $_GET['id']);
    $dummy->addCCO("Testuser1", "test@example.com");
    $dummy->addCCO("Testuser2", "test2@example.com");
    $dummy->fillMessage($myMessage);

    // now we send it!
    $dummy->send();
} catch (Exception $e) {
    echo $e->getMessage();
    exit(0);
}

And this is my send() function and my packheader() function: 这是我的send()函数和我的packheader()函数:

public function send() {
    if (is_null($this->to)) {
        throw new Exception("Must have at least one recipient.");
    }

    if (is_null($this->from)) {
        throw new Exception("Must have one, and only one sender set.");
    }

    if (is_null($this->subject)) {
        throw new Exception("Subject is empty.");
    }

    if (is_null($this->textMessage)) {
        throw new Exception("Message is empty.");
    }

    $this->packHeaders();

    $sent = mail($this->to, $this->subject, $this->textMessage, $this->headers);
    if(!$sent) {
        $errorMessage = "Server couldn't send the email.";
        throw new Exception($errorMessage);
    } else {
        return true;
    }
}


private function packHeaders() {
    if (!$this->headers) {
        $this->headers = "MIME-Version: 1.0" . PHP_EOL;
        $this->headers .= "Content-Type: text/html; charset=\"utf-8\"" . PHP_EOL;
        $this->headers .= "Content-Transfer-Encoding: 7bit";
        $this->headers .= "From: " . $this->from . PHP_EOL;
        $this->headers .= "Bcc: " . $this->cco . PHP_EOL;

        if (self::STRIP_RETURN_PATH !== TRUE) {
            $this->headers .= "Reply-To: " . $this->replyTo . PHP_EOL;
            $this->headers .= "Return-Path: " . $this->from . PHP_EOL;
        }
    }
}

And here I'm adding the CCO/BCC: 在这里我要添加CCO / BCC:

public function addCCO($name, $address) {
    $this->cco .= (is_null($this->cco)) ? ("$name <$address>") : (", " . "$name <$address>");
    return $this;
}

The mail that is send contains the BCC names in the body and not in the headers. 发送的邮件包含正文中的BCC名称,而不是标题中的BCC名称。 Does anyone see the problem? 有谁看到这个问题? The mail is sent to the $naam and $email correctly, only the BCC is not working. $email正确发送到$naam$email ,只有BCC不能正常工作。

You missed appending EOL here 你错过了在这里附加EOL

$this->headers .= "Content-Transfer-Encoding: 7bit" . PHP_EOL;
                                               //   ^ Here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM