Camen Design Forum

php mail and strange \r\n behaviour in headers part

append delete robert

Hi aweryone,

Im bild simple cms sistem with mail sent.

Afther one week without any problems next source start FAILed -

$headers .= "Importance: High\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit";

IF(mail($email, $subject, $message, $headers, " -f".$email) === TRUE)...

So, fail is in \r\n, between -
...MIME-Version: 1.0\r\ncontent-type: text/html; charset=iso-8859-1... - FAIL

...MIME-Version: 1.0\r\n content-type: text/html; charset=iso-8859-1... - TRUE
but html content of the mail is in plain text.

so im tray to change first letter of - content to ANSII - &-#-67;ontent... and works,
but again with html in plain text.

but\r\n between -
...content-type: text/html; charset=iso-8859-1\r\nContent-Transfer-Encoding: 8bit... is TRUE !

Allso, have to change prewious mail verification to next -
IF(mail($email, $subject, $message, $headers))...

Have no any idea, but i thing, problem is in hosting server.

Please, someone can help me ?

Thanks a lot.

Reply RSS


append delete #1. xj9

No offense, but most of what you're doing is a bad idea.

If you are going to be sending emails you should invest the time to learn (and integrate) a mailing library such as Swift Mailer[1] or PHPMailer[2]; it'll save you a lot of time and effort in the long run. If you want to learn how to send email robustly, read the source of one of the aforementioned libraries.

Doing things manually is a good learning exercise, but in production libraries and abstractions are a Good Thing.


append delete #2. robert1

i did it with PHP mailer .

"\r\n" strange behaviour was the problem on hosting server -and now it works good ! )

thanks a lot for anshwers )


(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn