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

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 1.9.7
    • None
    • Libraries
    • None
    • LAMP, PHP 5.2.13
    • Any
    • MOODLE_19_STABLE
    • Easy

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              skodak Petr Skoda
              matteo Matteo Scaramuccia
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: