Created
February 25, 2014 04:58
-
-
Save alchemycs/9202982 to your computer and use it in GitHub Desktop.
Don't accidentally send emails when testing email function from PHP (*nix including OS X)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# 1. Put this somewhere like /usr/local/bin/fakemail.sh | |
# 2. Set the permissions with: chmod a+x /usr/local/bin/fakemail.sh | |
# 3. Edit your php.ini and set: sendmail_path=/usr/local/bin/fakemail.sh | |
# | |
# Now your email will not be sent but logged to unique files that are timestamped. | |
# We use $RANDOM just to try and reduce collissions in case multiple emails are sent at the same time. | |
# | |
OUTDIR=/tmp/fakemail | |
mkdir -p $OUTDIR | |
OUTFILE=$OUTDIR/fakemail-$(date +%Y%m%d%H%M%S)-$RANDOM.txt | |
echo "CLI: $@" > $OUTFILE | |
while read line; do | |
echo "Line: $line" >> $OUTFILE | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick and dirty solution that ensures you don't accidentally send emails while testing. Particularly good for when doing bulk emails.
If you want to actually see the contents in an email client you are probably better to configure postfix with a re-write rule that sends everything to a specific testing email address.