954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Exclamation points at odd places in php email.

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.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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)));

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 
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.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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:

[PHP]$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");[/PHP]

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

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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
, 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.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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:

[php]$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");[/php] 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 [php]base64_decode()[/php] somewhere
:-O

w_3rabi
Junior Poster
160 posts since Dec 2006
Reputation Points: 18
Solved Threads: 9
 
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..

johnrenosh
Newbie Poster
1 post since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

aparnags
Newbie Poster
6 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

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 (,
, etc) was added to the body but produced errorsuntil 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.

Mogradjinn
Newbie Poster
8 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You