Sending Email from PHP on IBM i

With reliable email functionality being one of the top concerns of IBM i PHP users, we’ve made sure that Seiden PHP+ includes everything you need to send email. The PHP mail() function works well, as do components such as Zend\Mail and PHPMailer.

Over the past couple of years, we’ve been hearing from disappointed PHP users that mail() didn’t work in other community PHP distributions (and some builds of Zend Server). PHP mail() requires an external program that implements the sendmail interface. If your PHP distribution lacked sendmail or equivalent, you might have received a cryptic error message such as:

This article discusses your options for sending email using Seiden PHP+.

Classic mail() function

Although the mail() function has limitations, it is popular, so we support it. Our Seiden PHP+ distribution provides this underlying email capability by including an open source, sendmail-compatible email program called msmtp.

The msmtp program empowers your mail() function to send email over SMTP. Here is our documentation on how to set it up. To summarize: After you have installed CommunityPlus+ PHP, create a configuration file that defines your SMTP server. For example, substitute your mail server’s settings into the template below, and save it at /QOpenSys/etc/msmtprc.

Once that’s in place, mail() will use msmtp, which uses that configuration file, and you’re ready to go! If you run into any issues, check our documentation on setting up mail() for Seiden PHP.

You are not limited to using mail(). Below are our recommendations for more powerful, versatile mail options.

PHPMailer

If you’re willing to take on an additional package, we recommend PHPMailer as an alternative. It’s flexible and handles many use cases that the built-in mail() function does not. For example, it provides many things that would be impossible or difficult using just mail(), including UTF-8 support, attachments, and validation against bad inputs.

PHPMailer is a popular library used by many PHP projects, including major ones like WordPress. You can rely on it being a trusted, robust piece of software. If you’re using Composer like most modern PHP projects, then just run the following command to install it:

Laminas, Zend Framework, Laravel, and other PHP frameworks

The mail components of these frameworks are another popular option for sending mail. If you’re using these frameworks, then you likely have all the pieces you need.

It’s worth noting you can use Zend Framework without Zend Server. Zend Framework is a separate open-source project, that can be used independent of any PHP distribution.

Email Your Way

Whether you use mail(), PHPMailer, Zend\Mail, or other popular email components, Seiden PHP will support your choice. To learn more, get in touch for a free PHP upgrade consultation or to discuss letting our developers help you complete your next project.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.