The PHP Extension and Application Repository (PEAR) is a great set of utilities that can be incorporated into PHP scripts. I’ve used PEAR for most of the PHP projects I’ve developed over the past couple of years. Recently two of the PEAR packages have grabbed my attention.
Mail is a package for creating and sending e-mails. As such is very flexible since it allows creation of multi-part messages, with attachments, and copes with HTML and plain text messages. Unlike many PHP mailer classes, it copes with the variety of newline problems that vary according to platform. However, one of the things that is problematic is testing Mail out locally when one hasn’t got a working sendmail feature on the development machine.
However, I just discovered today that Mail now does send e-mails, so I needed to find out why. It turns out that MacOS X 10.3 (Panther) doesn’t ship with sendmail. Earlier versions of MacOS X did but enabling it was extremely difficult. 10.3 ships with Postfix because, quite simply, it’s better. How do you enable Postfix in 10.3?
- Edit /etc/hostconfig
- Locate the setting for
MAILSERVER and change it to YES
- Save the file
- Reboot, or sudo Postfix start
That’s it. Sure there’s other configuration that can be done, but that was all I needed to do. What’s more in my installation MAILSERVER was already set up and Postfix was therefore already enabled. So, testing my PEAR Mail scripts locally was possible straightaway.
The second package that I’ve recently discovered is Log. It provides file, database, window, display, syslog, mail, and console logging facilities. You can have multiple loggers operating at the same time, and indeed create composite loggers that log to more than one place. It also allows observers to be attached to loggers. I am using it in the following way for my current project.
- A file based logger for all levels of information, so various types of information go to the file. Looking at logs on MacOS X is easy since I just open the file in console and it keeps me up to date with the various events that I’ve filtered into the log.
- If I’m logged in to the website that I’m testing I get another logger, which is a screen based logger. This is a second window which pops-up automatically when I visit a web page.
Loggers can also be attached to PEAR and PHP error reporting functions. The latter is very useful, albeit it cannot yet capture Fatal errors.