PHP mail function randomly adds a space to message text

I have a very simple PHP script, something like:

while ($condition){ echo "<a href="thanks.php?id=".$id."> THANKS </a>"; } 

Of course, I have a bit more code, but that doesn't matter. Once I created this piece of code, the script sends an email to the user.

Inbox

The links are in order, on each line except LAST ONE it shows the link as follows:

  tha nks.php?id..... 

It adds a space between the code.

This only happens with hotmail. Gmail, yahoo and everything else work fine.

+8
php email space hotmail
source share
4 answers

I know this is late, but there is an alternative solution that worked for me:

Use this line to encode the entire message with base64:

 $message = chunk_split(base64_encode($message)); 

Then add this heading:

 $headers .= "Content-Transfer-Encoding: base64\r\n\r\n"; 

This will tell the email client that your message is base64 encoded.

+11
source share

The karancan solution probably works, but the main reason is what Hobo said. The mail function inserts a line break every 900 characters (I think). Therefore, if you create your $ message with a bunch of $message .= "more text"; , you will encounter this error if this string is more than 900 characters. This is confusing because the spaces seem intermittent, especially if you are creating an HTML message because sometimes line breaks will appear in completely soft places.

A simple solution is to add \r\n\ to the end of the lines.

Interestingly, these forms work:

 $message .= "<tr><td>1</td><td>2</td>\r\n"; $message .= '<tr><td>1</td><td>2</td>'."\r\n"; 

But this is not so:

 $message .= '<tr><td>1</td><td>2</td>\r\n'; 

\r\n must be surrounded by double quotes, otherwise the characters will simply be added to the text instead of creating a carriage return / line.

+10
source share

Faced the same problem and tried most of these solutions, but this did not work for me. The line seems to be too long for the mail function, it adds a space of about 900 characters. Thus, the following solution for adding a dictionary worked for me.

mail ($ to, $ subject, wordwrap ($ message), $ headers);

+6
source share

I saw sendmail insert characters when lines are too long. This is not the case (how other clients handle this normally), but I am wondering if hotmail has a line length limit that you click on.

It doesn't matter if you insert a new line into your echo , i.e.

 while ($condition){ echo "<a href=\"thanks.php?id=".$id."\"> THANKS </a>\n"; } 
0
source share

All Articles