Tag Archives: Zend Framework

Sending mails from a Zend application

If you are making an application that needs to send out e-mails to for example hundreds of your users, then you don’t really want to actually send them e-mails when testing your application in a development environment. They would totally not appreciate getting multiples of your test e-mails, probably littered with loads of debugging code.

However, in Zend Framework you can have a different configuration for your development environment. One of these configuration items is the mail transport system. If you tell Zend to use the following for your development environment:

resources.mail.transport.type = Zend_Mail_Transport_File
resources.mail.transport.path = APPLICATION_PATH "/../mails"

then the Zend Framework will put all e-mails sent using the Zend_Mail class, in this mails directory in your project’s root directory. This way, you can safely test all the out-going e-mails that are sent by your application, and check them out in the mails directory.

There is still one more thing to do. If you do the above, you will notice that Zend creates *.tmp files that are in a certain ugly MIME encoding format (7bit, quoted-printable or base64). What is more, you will have a hard time checking the HTML layout of your HTML e-mails, since you’ll only see HTML code in the *.tmp files for your HTML e-mails, which are also encoded in the aforementioned ugly mail encoding.

Add mutt to your toolkit, configure your Zend mail transport to put the mails in the new directory of the mutt tree, and you’ll be able to access your e-mails using mutt!

First the Zend configuration:

resources.mail.transport.type = Zend_Mail_Transport_File
resources.mail.transport.path = APPLICATION_PATH "/../mails/new"

Then install mutt and prepare the directories:

sudo apt-get install mutt
mkdir -p mails/tmp mails/cur mails/new
chgrp www-data mails/new
chmod g+w mails/new

Start mutt, telling it to use the mails directory:

mutt -f mails

And there you go, you’ll be able to see incoming mails, sent from your Zend application. No need to fiddle with the addTo() calls that could be everywhere.

To check the HTML version in your mutt e-mail client, open the e-mail, hit v to see the attachments, navigate to the text/html part, hit Enter, and mutt will open it in your default web browser.

Zend Framework 1 Extension Library and Composer

Maybe I am a bit late to get on the Composer bandwagon, but a colleague was adamant about it and convinced me to use Composer in our projects. The benefit of using Composer with your PHP applications is that it will download any library dependencies for you, and take care of the autoloading of classes. So I enabled Composer in my Zend Framework 1 Extension library, with a Zend Framework 1.* dependency. Read on how to get the libraries using Composer!

Continue reading Zend Framework 1 Extension Library and Composer

Multi-lingual views in Zend Framework 1

Ever felt like this?

Build us a multilingual website

If so, do read on. Because it has become easier.

Do you want to quickly organize your multi-language website in Zend Framework, such that you can easily add languages without breaking the website? And from there, progressively translate pieces of your website? Imagine a website where you have a handful of static content – think of about pages, policy pages and disclaimer pages – and you want to easily add translated pages to your system, without having to go through programming the logic of selecting the right view for these pages.

Look no further, for the ZF1E library offers exactly that solution. Using the built-in MultiLanguage resource, it will determine which language part of your website your visitor is accessing, and grab the correct view for that language.

Continue reading Multi-lingual views in Zend Framework 1

Cookies and Internet Explorer

Cookies for everybodyImagine you have a Zend Framework (version 1) application on a domain example.org, and another on a domain admin.example.org. They both have authentication mechanisms using Zend_Auth. This authentication information is stored in a browser cookie. Now I came across this problem that being logged in on both systems does not pose any problems with Google Chrome or Mozilla Firefox, but for some very strange reason, Microsoft Internet Explorer didn’t like it. The admin.example.org domain would be broken if you were logged in on example.org first. The server spewed out a 500 Internal Error, so I checked in the server logs to see what the heck was happening.
Continue reading Cookies and Internet Explorer

Multi-lingual resource in Zend Framework 1

To continue my previous post, but this time tie it to the Zend Framework (version 1), I have added a ZF application resource plugin to my library which redirects the visitor to the correct language sub-domain according to his browser’s settings. This plugin will take care of the redirection logic, and keep all the necessary information for the application to provide the user with the GUI elements for switching languages.

Continue reading Multi-lingual resource in Zend Framework 1