With reliable email functionality being one of the top concerns of IBM i PHP users, we’ve made sure that CommunityPlus+ 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:
sh: -t: not found
This article discusses your options for sending email using CommunityPlus+ PHP.
Classic mail() function
Although the mail() function has limitations, it is popular, so we support it. Our CommunityPlus+ 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
defaults auth on tls on logfile /QOpenSys/var/log/msmtp.log account example host smtp.example.com port 587 from firstname.lastname@example.org user youruser password yourpw account default : example
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 CommunityPlus+ PHP.
You are not limited to using mail(). Below are our recommendations for more powerful, versatile mail options.
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:
composer require phpmailer/phpmailer
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 CommunityPlus+ 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.