Hey, I have a script that sends a user an html-formatted email. Usually once per email, there is an exclamation point popping up in the middle of the email. I've read somewhere about this happening because of some limit at 1000 character limit, and it could be around that point, I'm too lazy to count. But assuming it is, how do I sto!p this f!reaking exlamation point fro!m poping up?!

Also, they don't happen every time. I'd estimate 2 out of every 10 emails don't have the rogue exclamation point.

Recommended Answers

All 9 Replies

If you are seeing unwanted line breaks preceded by exclamation marks ("!") in the emails you send with mail(), you may be having the same problem I had: exceeding the maximum line length (998 chars) specified in RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html).
You can get around this restriction by using base64 encoding: add a "Content-Transfer-Encoding: base64" header and encode the contents with
$base64contents = rtrim(chunk_split(
base64_encode($contents)));

If you are seeing unwanted line breaks preceded by exclamation marks ("!") in the emails you send with mail(), you may be having the same problem I had: exceeding the maximum line length (998 chars) specified in RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html).
You can get around this restriction by using base64 encoding: add a "Content-Transfer-Encoding: base64" header and encode the contents with
$base64contents = rtrim(chunk_split(
base64_encode($contents)));

Well I'm not getting any line breaks, just the exclamation points, but I'll look into that anyway.
Thanks.

Ok, well I tried the base64 encoding, and I now the email just sends a bunch of jibberish, like this:

PGh0bWw+PGJvZHkgbGluaz0ibmF2eSIgdmxpbms9IiMwMDMzNjYiPjxjZW50ZXI+PHRhYmxlIHdp ZHRoPSIxMDAlIj48dHI+PHRkIHZhbGlnbj0iYm90dG9tIiB3aWR0aD0iNTAwIiBoZWlnaHQ9IjEw MCIgYmFja2dyb3...

Anyway, I'm not even sure I was doing it right, maybe you could look at my mail code here, and tell me if I was incorporating it correctly. I've got the entire email content stored in a variable called $msg. After putting together the message, I have this code:

$msg = rtrim(chunk_split(
base64_encode($msg)));

@mail($to, $subject, $msg, "From: $from\nContent-Type: text/html; charset=iso-8859-1; Content-Transfer-Encoding: base64");

So let me know if I'm not doing it right. These exclamation points are killing me! Thanks.

I've just noticed that I think it is inserting line breaks, but they're not showing up in the email itself, because they're not html <br>, but probably something like a \n or something like that. And the exclamation point isn't showing up much anymore, but a space is, and the annoying thing is, it's now happening right around or in a hyperlink, which obviously screws up the hyperlink! Well I've inserted some characters to shove it out of the way of the hyperlink for now, but this has got to stop.

Anyway, so if I need to do something else to stop this, let me know.
Thanks.

Ok, well I tried the base64 encoding, and I now the email just sends a bunch of jibberish, like this:

Anyway, I'm not even sure I was doing it right, maybe you could look at my mail code here, and tell me if I was incorporating it correctly. I've got the entire email content stored in a variable called $msg. After putting together the message, I have this code:

$msg = rtrim(chunk_split(
base64_encode($msg)));

@mail($to, $subject, $msg, "From: $from\nContent-Type: text/html; charset=iso-8859-1; Content-Transfer-Encoding: base64");

So let me know if I'm not doing it right. These exclamation points are killing me! Thanks.

i havent tried to email in php before
but dont you need to use

base64_decode()

somewhere
:-O

If you are seeing unwanted line breaks preceded by exclamation marks ("!") in the emails you send with mail(), you may be having the same problem I had: exceeding the maximum line length (998 chars) specified in RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html).
You can get around this restriction by using base64 encoding: add a "Content-Transfer-Encoding: base64" header and encode the contents with
$base64contents = rtrim(chunk_split(
base64_encode($contents)));

wow..... ur soln really helped me... i was really frustrated by the exclamation character in the mails ent by php mail().....

Thanks..

Hi John,

I know its a old thread, however i'm faced with the same issue, i tried the base64 solution and i'm getting mail like this:

PGh0bWw+PGJvZHkgbGluaz0ibmF2eSIgdmxpbms9IiMwMDMzNjYiPjxjZW50ZXI+PHRhYmxlIHdp ZHRoPSIxMDAlIj48dHI+PHRkIHZhbGlnbj0iYm90dG9tIiB3aWR0aD0iNTAwIiBoZWlnaHQ9IjEw MCIgYmFja2dyb3...

, you have mentioned that finally its working for you, can you please provide me with additional inputs to fix this? Thanks a million in advance for your time & comment

Aparna

Apologies that this is an old thread revived but I had the same problem, now seemingly solved (it's not clear from the posts whether my situation was being caused the same way).

Exclamation marks were appearing in semi-random places and length was not the issue here. It seems that my problem was in not forming HTML well.

Headers were set using:

$headers = "From: $Name <$from>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

HTML (<p>, <br/>, etc) was added to the body but produced errors until I also added at the beginning of the content:

$mail_body = "<html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type content='text/html; charset=utf-8' />";
$mail_body .= "<title>Document</title></head>\n<body>\n";

And similarly at the end:

$mail_body .= "</body></html>";

No errors since.

If you are seeing unwanted line breaks preceded by exclamation marks ("!") in the emails you send with mail(), you may be having the same problem I had: exceeding the maximum line length (998 chars) specified in RFC 2822 ( http://www.faqs.org/rfcs/rfc2822.html ).
You can get around this restriction by using base64 encoding: add a "Content-Transfer-Encoding: base64" header and encode the contents with
$base64contents = rtrim(chunk_split(
base64_encode($contents)));

Wow this fixed my exclamation mark issue i had been strungling to fix for almost a month now!!!

  $headers = "From:someone@somewhere.com\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=utf-8\r\n";
  $headers .= "Content-Transfer-Encoding:base64 \r\n";

  $message = "THIS IS A TEST";


  $messagebody= $base64contents = rtrim(chunk_split(base64_encode($message)));

    mail(tofoo@bar.com, $subject, $messagebody, $headers )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.