diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 5a528d8..d0d6c52 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -2090,8 +2090,7 @@ class PHPMailer foreach ($this->to as $toaddr) { $toArr[] = $this->addrFormat($toaddr); } - //Fold long lists the same way as the To header, mail() keeps CRLF + WSP folds intact - $to = trim(substr($this->addrAppend('To', $this->to), strlen('To:'))); + $to = trim(implode(', ', $toArr)); //If there are no To-addresses (e.g. when sending only to BCC-addresses) //the following should be added to get a correct DKIM-signature. @@ -2648,18 +2647,17 @@ class PHPMailer $addresses[] = $this->addrFormat($address); } - //Fold between addresses so that no line exceeds the RFC 2822 line length limit + //Fold between addresses so that no line exceeds the RFC 5322 limit, + //leaving room for the comma at the end of a folded line $header = $type . ': ' . array_shift($addresses); $lineLength = strlen($header); foreach ($addresses as $address) { - //The address goes after ', ' and must still leave room for the ',' that ends - //the line if the next address gets folded - if ($lineLength + strlen(', ') + strlen($address) + strlen(',') > static::MAX_LINE_LENGTH) { + if ($lineLength + strlen($address) + 3 > static::MAX_LINE_LENGTH) { $header .= ',' . static::$LE . ' ' . $address; - $lineLength = strlen(' ') + strlen($address); + $lineLength = strlen($address) + 1; } else { $header .= ', ' . $address; - $lineLength += strlen(', ') + strlen($address); + $lineLength += strlen($address) + 2; } }