Sending e-mail with alternative parts plus attachments

Today I was working on my MailService component in a ZF2 project. For this specific project I needed to be able to support alternative parts for text and html combined with attachments. The alternative parts are to allow less sophisticated mail readers, not capable of rendering html, to still read the message. When sending mail using the Zend\Mail\Message class you have to create a Zend\Mime\Message object and assign this object to the body of Zend\Mail\Message, using setBody(). The Zend\Mime\Message object contains the actual parts of the message and the Zend\Mail\Message is responsible for the mail headers. The default content-type of a Zend\Mail\Message is 'multipart/mixed'. This is usually perfect if you're only sending one text part and optionally one or more attachments, but if you want to support alternative parts (requires content-type 'multipart/alternate') AND attachments (requires 'multipart/mixed') then you have a little ...

(Read more...)

Adding custom fields to ZfcUser register form

The ZfcUser module ZfcUser is a Zend Framework commons module that handles basic use cases related to users. It takes care of handling the registration, logging in, logging out, authenticating and user profile management. It is a very well written module, allowing the user of the module to change the behavior without having to hack in the module’s codebase. Tip: never change the code of a vendor module. The problem A common use-case for the ZfcUser module is to add more fields to the registration form (i.e. a firstname and lastname or date of birth). Of course when I needed this functionality myself, I did a quick search and figured I wasn’t the only one needing this. However there were no real conclusive answers of how to do this. I did find one article[1] that helped me to get started. What I needed What I needed was the following: Add the extra fields to the registration form; Make sure the fielddata gets saved to the database when the user registers; Adding validators and filters to the custom fields; Changing the validator messages of the standard ZfcUser userfields; Changing the order of the fields in my registration form. How I accomplished it ...

(Read more...)