Have you ever tried to send HTML email using PHP? Sending plaintext email is quite straight forward and easy, and if you have the energy to write your own functions, sending HTML email can be pretty simple too. Half the problem is writing functions that can be ported around to different projects quickly and easily.
PHP Objects made this much easier to do, and since then I’ve been swapping objects in and out of various different parts of the code, and across different applications. I realised the other day that the one I make the most use of is my mail message object. So I thought I would open it up in the event that you also found it useful!It is really simple and lightweight – which means that it works, but it doesn’t offer hundreds of functions like some of the really sophisticated packages out there.
It supports sending plaintext only, or HTML with a plaintext component. I haven’t yet added attachment functionality, because I try to avoid sending attachments by email. If you’re curious as to why – well attachments can clog up inboxes (especially for those on slower connections), and also because it is difficult to track who opens your attachments. If you send dynamic hyperlinks along with your message, that point to the location of the downloadable files, then at least you can track who is actually accessing them!
If you want an object that dynamically supports attachments as well, then let me know, and I’ll upgrade this object so that you can do that.
In relation to email, another common problem is the inclusion of far too much email message content in the actual HTML file – I’ve found that a lot of my code, and those from other developers, contained message templates within the body of the code (much like you’ll see in the example file in the attached download). So I’ve also knocked together a message template manager that can be used with this object – I’ll release that shortly too.
In the meantime however, I have included two files in the ZIP file for download, and one of them is an example that guides you through how to make messages using the object. It’s licensed under GPL, so you can download it and use it in your projects – if you do, I ask that you link back and let me know how you’re using it!
I request that you don’t host this ZIP for download on your servers, as I will update the object with enhancements that people send back, or bug fixes if anybody finds them!Share on Facebook