Last active
July 12, 2016 19:11
-
-
Save ScreamingDev/b3ac03ef37c9f3b235c1 to your computer and use it in GitHub Desktop.
PHP local send mail (/usr/local/bin/sendmail)
This file contains hidden or 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
#!/usr/bin/php | |
<?php | |
$input = file_get_contents('php://stdin'); | |
preg_match('|^To: (.*)|', $input, $matches); | |
$filename = tempnam('/var/log/mail', date('ymd-his-') . $matches[1] . '.'); | |
file_put_contents($filename, $input); |
This file contains hidden or 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
vi /usr/local/bin/sendmail | |
# copy the above code in it | |
chmod 755 /usr/local/bin/sendmail | |
# it doesn't need to be "/var/log/mail" | |
# it can be any folder you like | |
# just change it in the sendmail-code above and here | |
mkdir -p /var/log/mail | |
chmod 777 /var/log/mail | |
# in php.ini change the sendmail_path | |
# which can also be done via .htaccess | |
sendmail_path = /usr/local/bin/sendmail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used to work fine but when upgraded to Ubuntu 16.04 / PHP7.0 it stopped working. Any ideas?
EDIT (fixed): line endings should be \n only. With \r\n bash cannot find php LOL