-
Bug
-
Resolution: Duplicate
-
Minor
-
None
-
1.9.7
-
None
-
LAMP, PHP 5.2.13
-
Any
-
MOODLE_19_STABLE
-
Easy
We developed a custom module to send reports back to some emails, usign TO, CC and BCC fields. Under some circumstances (no smtphosts defined i.e $this->Mailer = "mail"), the bundled PHPMailer library, instantiated through get_mailer(), misses to deliver emails to CCed people.
We found the reason of such a failure to be in the CreateHeader internal method:
...
|
// To be created automatically by mail()
|
if($this->Mailer != "mail")
|
{
|
if(count($this->to) > 0)
|
$result .= $this->AddrAppend("To", $this->to);
|
else if (count($this->cc) == 0)
|
$result .= $this->HeaderLine("To", "undisclosed-recipients:;");
|
if(count($this->cc) > 0)
|
$result .= $this->AddrAppend("Cc", $this->cc);
|
}
|
|
$from = array();
|
$from[0][0] = trim($this->From);
|
$from[0][1] = $this->FromName;
|
$result .= $this->AddrAppend("From", $from);
|
|
// sendmail and mail() extract Bcc from the header before sending
|
if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
|
$result .= $this->AddrAppend("Bcc", $this->bcc);
|
...
|
Version 2.0.4 of PHPMailer acts like below:
...
|
/* To be created automatically by mail() */
|
if($this->Mailer != 'mail') {
|
if(count($this->to) > 0) {
|
$result .= $this->AddrAppend('To', $this->to);
|
} elseif (count($this->cc) == 0) {
|
$result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
|
}
|
}
|
|
$from = array();
|
$from[0][0] = trim($this->From);
|
$from[0][1] = $this->FromName;
|
$result .= $this->AddrAppend('From', $from);
|
|
/* sendmail and mail() extract Cc from the header before sending */
|
if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
|
$result .= $this->AddrAppend('Cc', $this->cc);
|
}
|
|
/* sendmail and mail() extract Bcc from the header before sending */
|
if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
|
$result .= $this->AddrAppend('Bcc', $this->bcc);
|
}
|
...
|
Shortly, CC is managed the same as BCC as it should be in terms of email headers.