I am sending HTML emails using the PHP mail function and have found that email clients are inserting single space characters at regular intervals. This is inconvenient when part of the email is a url.
I devised a test script to illustrate this:
<?php
$message = '<html><body>';
$message .= '</body></html>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$message .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456<br>';
$headers = 'From: sender@domain.com' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n";
$subject = 'Inserting spaces into HTML';
mail('receiver@domain.com', $subject, $message, $headers);
?>
In Outlook and Apple Mail, but not MailHog, this is the result:
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456 78901234567890123456789012345678901234567890123456
Note where the above has wrapped where the space occurred.
I have tried this with more lines and found that if you count the characters in the tags and the spaces themselves, this occurs every 998 characters (I think).
The simple workaround is to pad the preceding HTML with formatting so that the space does not occur within the url.
Does anyone have any explanation?