This story contains no information of interest to anyone what-so-ever.
But it annoyed me, so let me vent.
I was already over my time-estimate, and I had a bug. It was strange, the system was sending out two emails and one had an exclamation mark; just randomly right in the footer – But the other was fine. After staring at my code and deciding that there was nothing wrong I decided to view-source in the browser – Yup, email had an exclamation mark right in the middle.
But I wasn’t putting it in there, and the code to attach the footer to each email was exactly the same. However only one email was displaying an exclamation mark.
See this project was in .php on a linux server – I’m not a php guru, nor a linux expert – previous to last month I had written approximately 50 lines of php code, and I’ve run linux, well never.
So I was convinced it was my bug, something I’d done wrong, something about the php_mail() function that I didn’t know about – It didn’t help that the server hadn’t been patched since 2004 and was still running php 4.2 so I couldn’t use any of the email libraries that kept being recommended in my google searches and promised to make my life easier.
So I entered a new test order into the system, and I got my two emails – One with an exclamation mark and one without, but this time the exclamation mark had moved. My previous testing at always shown it in the same place.
Test and measure, it’s the scientific method.
So I try entering a new order, this time adding exactly 4 characters to the address on the order form. This time the exclamation mark has moved exactly 4 places to the left.
Ah ha, I’ve got something! – I thought to myself. The system was no longer random, no longer chaotic, I had something deterministic – I had no idea why but the length of the email was causing an exclamation mark to be inserted
I modified my code output the email to the browser before sending it to php_mail() – No exclamation mark, formating all correct, everything fine. But when I recieved the email – exclamation mark.
It turns out that sendmail inserts an exclamation mark into an email if it receives a string that is too long without a line break. Why? I have no idea.
Because I was sending HTML I wasn’t bothering to insert line breaks ‘\n’ into my string before passing it to php_mail() – Instead I was using <br>
So some programmer, somewhere at sometime working on sendmail decided that if a string was too long they would split it up by inserting an ! character – This is probably some strange legacy thing from eons ago before HTML was even invented.
And only one of the emails was inserting an exclamation mark because the other was under the threshold for the maximum length before sendmail inserts an exclamation mark.
So that’s a boring story about how I lost 4 hours of my life and one of the stupid reasons why software is often over budget and over schedule.