Skip to content

Instantly share code, notes, and snippets.

@ScreamingDev
Last active July 12, 2016 19:11
Show Gist options
  • Save ScreamingDev/b3ac03ef37c9f3b235c1 to your computer and use it in GitHub Desktop.
Save ScreamingDev/b3ac03ef37c9f3b235c1 to your computer and use it in GitHub Desktop.
PHP local send mail (/usr/local/bin/sendmail)
#!/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);
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
@uuencode
Copy link

uuencode commented Jul 12, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment