1

I'm getting an error in my mail() function.

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

While I was googling I came across some suggestions. but removing multiple new lines in additional_headers did not work. How can I fix this?

$separate =md5(time());
$el=PHP_EOL;
$headers  = "From: ".$sndr.$el;
$headers .= "Reply-To: ".$sndr.$el;
$headers .= "MIME-Version: 1.0".$el; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separate."\"".$el; 
$headers .= "Content-Transfer-Encoding: 7bit".$el;
$headers .= "This is a MIME encoded message.".$el;
$headers .= "--".$separate.$el;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$el;
$headers .= "Content-Transfer-Encoding: 8bit".$el;
$headers .= $message.$el;
Community
  • 1
  • 1
Bekki
  • 719
  • 2
  • 12
  • 20
  • 1
    don't build your own mime emails. just use phpmailer or swiftmailer. pretty much ALL of what you're doing will be reduced to just a couple lines of code. and note that PHP_EOL is useless. it's the local end-of-line character, which may or most likely WILL NOT be the eol character required for email. – Marc B Aug 05 '15 at 19:25
  • @MarcB. thanks. But these are existing codings that we've being using for couple of years. This issue came up out of nowhere. So shifting to swiftmailer or phpmailer will be a major job. – Bekki Aug 05 '15 at 19:29
  • Please stop [reposting](http://stackoverflow.com/questions/31791294/phps-mail-function-not-showing-html-email). If for some reason you're unwilling to use the easier option, but want your unreliable code patched temporarily, add a bounty instead. – mario Aug 05 '15 at 19:43
  • possible duplicate of [Error with PHP mail(): Multiple or malformed newlines found in additional\_header](http://stackoverflow.com/questions/30887610/error-with-php-mail-multiple-or-malformed-newlines-found-in-additional-header) – bufh Aug 05 '15 at 20:55

1 Answers1

1

You're inserting your message into your headers:

$headers .= $message.$el;

so you'll have

From: someone@somewhere.com
blah: blah
Hi mom!
Content-type: blah blah

which is an illegal email.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thanks for your input. I'm having `$message = " TEXT` defined at the top. Is that still illegal? Could you kindly explain how it is illegal? – Bekki Aug 05 '15 at 19:32
  • 1
    email has two parts: headers, and body, separated by two new lines. e.g. `$header\n\n$body`. you've mixed non-header content into the headers of your email, so in medical terms, you decide to use the patient's IV line to pump air into their lungs, and killed them. – Marc B Aug 05 '15 at 19:33