Practical Web Programming

Friday, November 07, 2008

Lessons from the PHP Mail Function

Oh man, I got screwed.

Yesterday, I was testing the mail function that I wrote for the Helpdesk web application that I did. I was so sure the function works because I always receive email every time I submit a test ticket entry.

I wrote the function to send an email only to me when it is the development server and send to everybody else in our team when it's in the production. The human (or idiot :)) that I am, I miss to change the $to parameter of the mail function. So instead of only me receiving the email, our entire team for the whole US southern division received more than ten test emails. I only discovered the bug when my fellow developer called my attention that he keeps receiving a test email. Fortunately, those email all contains the title 'Test'.

Lesson learned? First, always test your application like you are in the production server. Had I not put 'Test' as the title, it would have been mistaken for a legit email. Second, don't think you already changed your source code somewhere, double check it, if not triple. Oftentimes, you are so sure you have it right, only to found out it's not.


Recent Post