Reputation: 3163
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", "[email protected]");
$dummy->addRecipient($naam, $email);
$dummy->fillSubject("Jouw ruiling #" . $_GET['id']);
$dummy->addCCO("Testuser1", "[email protected]");
$dummy->addCCO("Testuser2", "[email protected]");
$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:
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:
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. Does anyone see the problem? The mail is sent to the $naam
and $email
correctly, only the BCC is not working.
Upvotes: 0
Views: 128
Reputation: 3867
You missed appending EOL here
$this->headers .= "Content-Transfer-Encoding: 7bit" . PHP_EOL;
// ^ Here
Upvotes: 2