Rob Allen has a new post today showing you how to use the ZendMail component of the Zend Framework 2 to send attachments with multipart emails. A multipart email allows you to combine both the HTML and plain text versions of the content into a single email.

He includes the full code for the example first: a "sendEmail" function that sets up the MIME and plain-text parts and uses the "MimeMessage" and "MimePart" objects to attach the file. He goes through each of the parts of the script and describes what's happening and how that changes the content of the email. You can find out more about the ZendMail component in this section on the Zend Framework manual.

Like every product, Natural Load Testing needs to send some mail, having written and re-written a bunch of different blocks of mail code over the years, I wanted to come up with something that would work now, and continue to serve us well into the future.

He chose Zend_Mail to fulfill some of his requirements (multipart emails, sending custom emails, templates for automatic emails) and includes some sample code showing it at work. The result is an object that can be created and, by calling a "basic" method, can send an email based on an HTML template (using the HTML Email Boilerplate for the base styling).

PHP has a very simple mail function which is used very often for basic text mail messages. What if you need to attach files or if you need to send your e-mail messages via SMTP? Than itâ€™s time to use a more advanced script. This is because the standard mail function has only limited standard capabilities.

Snippets of code are included for each of the three showing how to send a simple email with the usual "To", "From" and body contents. All of the tools have the ability to include attachments, but that's not included here.

I think a staging environment is more appropriate to actually have email being sent out. Nevertheless, it has made testing any email functionality a little cumbersome. I've done a little research, and have found two ways to tackle the problem. I've also included code samples and other resources to get you started.

The first method - the transport class - uses the Zend_Mail_Transport component (and interfaces) to set the transport for the application and handle the routing from an extension of the Abstract class. The second method involves changes to system settings in the php.ini and adding in a simple script to force a forward to the right address. Windows users can also use fakemail to accomplish a similar thing.

On the ElectricToolBox.com blog there's a quick post looking at method chaining in a Zend Framework application:

Having used the Zend Framework on a couple of projects and spent a lot of time reading the documentation I discovered the use of method chaining. This post looks at how to use method chaining in PHP.

His examples include a comparison between a method-chained Zend_Mail example and a non-chained method with each line augmenting the same object over and over. He also includes the simple-as-pie method that lets you use chaining in your own applications - returning the object itself.

On the Developer.com website today, Jason Gilmore has a new tutorial covering a important feature of any based PHP install (unless disabled, of course) that is widely taken advantage of - sending emails.

Email plays a crucial role in website development, whether you'd like to confirm a new registrant's email address, recover a lost password, or provide prospective clients with a convenient means to contact you. [...] In this tutorial, I'll introduce you to several solutions for sending email using PHP, including PHP's native mail() function, PEAR's Mail package, and the Zend Framework.

He starts with some of the fundamentals of mail - the difference between POP3 and SMTP, Sendmail, etc - before moving on to an example of the mail function's usage. He does the same with the PEAR Mail package and the Zend_Mail component of the Zend Framework.

On the Techfounder blog (from Eran Galperin) there's a quick tutorial about using the Zend_Mail component of the Zend Framework to send both normal, plain-text emails and ones with MIME attachments.

Using PHP's built in function (aptly named mail() ) is relatively straightforward - until you need slightly more advanced features, such as adding and encoding email headers or sending multiple mails efficiently. Fortunately, the Zend Framework comes with a very capable mail component called Zend_Mail.

He shows how to send a simple email, do something a bit more complex with a custom SMTP server, read messages from a remote POP3 email box and how to attach a binary file/message.