Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-21835

get_mailer: no mail sent to CCed people when using IsMail i.e. no smpthosts defined

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 1.9.7
    • Libraries
    • 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.

            skodak Petr Skoda
            matteo Matteo Scaramuccia
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.