PHP mail function randomly adds a space to message text

Andy picture Andy · Apr 3, 2012 · Viewed 8.8k times · Source

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 it doesn't matter. Once I had created this piece of code, the script sends an email to the user.

THE INBOX

The links are okay in every single line, except the LAST ONE shows the link this way:

    tha nks.php?id.....

It adds a space in between the code.

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

Answer

karancan picture karancan · Feb 7, 2013

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

Use this line to encode your entire message using base64:

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

Then, append this your header:

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

That will tell the mail client that your message is base64 encoded.