Warning: mail(): Multiple or malformed newlines found in additional_header in

UPDATE - After running this through line by line pretty much, the error occurs on the last line which is the $headers .= “–”.$separator.“–”; line. If I don’t put that line in it attaches the PO but it cannot be opened or viewed. If I do put it in it gives me the malformed header message. Does anyone know what the format of this is supposed to be?

ORIGINAL MESSAGE - Just recently, the emails I send from my system with pdf attachments stopped working. I am getting the error above Warning: mail(): Multiple or malformed newlines found in additional_header in. From my limited research it seems PHP has changed the way they handle headers? This is in a production system and I need to get it back up and running by tomorrow morning so any input would be greatly appreciated. The system is PHP 5.5.31 and on another dev system with the same code running that is 5.5.23 it runs just fine. From what I can gather the upgrade to .31 made a change to the way they handle headers and that it won’t take additional headers, but I’m not sure what that means. I did have .$eol.$eol in there and removed those to a single $eol but that didn’t fix it. The code I am running and that has been running without any issues for the last year is:

	$subject = "Requested PDF"; 

    			$this->pdftype='';
			// email stuff (change data below)
			$to = $maillist[1]; 
			$from = "admin@mysite.com"; 
			// a random hash will be necessary to send mixed content
			$separator = md5(time());
			// carriage return type (we use a PHP end of line constant)
			$eol = PHP_EOL;
			// attachment name
			$filename = badchars($this->content[1]['poname']) . ".pdf";
			// encode data (puts attachment in proper format)
			$pdfdoc = $pdf->Output("", "S");
			$attachment = chunk_split(base64_encode($pdfdoc));
			// main header (multipart mandatory)
			$headers  = "From: ".$from.$eol;
//			$headers  = "From: ".$maillist[1].$eol;
			$headers .= "Cc: ".$maillist[2].$eol;
			$headers .= "Bcc: ".$maillist[3].$eol;
			$headers .= "MIME-Version: 1.0".$eol; 
			$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
			$headers .= "Content-Transfer-Encoding: 7bit".$eol;
			$headers .= "This is a MIME encoded message.".$eol.$eol;
			// message
			$headers .= "--".$separator.$eol;
			$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
			$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
			$headers .= $message.$eol.$eol;
			// attachment
			$headers .= "--".$separator.$eol;
			$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
			$headers .= "Content-Transfer-Encoding: base64".$eol;
			$headers .= "Content-Disposition: attachment".$eol.$eol;
			$headers .= $attachment.$eol.$eol;
			$headers .= "--".$separator."--";
			// send message
		$retval = mail($to, $subject, "", $headers);

I tried making all the $eol.$eol segments to $eol but to no avail.

Thanks for the help.

Ignore this, I have moved the mail function over to phpMailer.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.