While you’re testing email functionality on a website, you don’t want to accidentally send out mails to all your (or your clients’) end users! There are a few ways to prevent this. Here’s the simplest one I’ve found so far. It allows you to redirect all outgoing email from PHP to a local user (you, for example), so that you can read it with any ordinary mail client. You can also redirect to any arbitrary external email address you own.
Create a shell script with the following content:
#!/bin/bash REDIRECT="$1" shift /usr/sbin/sendmail -i "$@" "$REDIRECT"
Make it executable, then add a line to
sendmail_path = "/path/to/script.sh username@localhost"
Reload Apache, and you’re done.
sendmailcommand directly in
php.ini, but you can’t: Postfix’s
sendmailexpects its arguments in POSIX order (options first), and PHP may add a
-foption after the hardcoded email address, which would be interpreted as a recipient address beginning with
You can also redirect email to a different address for each virtual host, by setting the
sendmail_path option via
I’ve tested this with Postfix on Ubuntu, but I believe it should work in other configurations too.