Last active
September 16, 2023 23:09
-
-
Save x-magic/3ba692c7ebc992e263d53c5054c548d2 to your computer and use it in GitHub Desktop.
A script to imitate sendmail (to capture mails to be saved locally) for PHP using PHP
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
<?php | |
// To use this script, set | |
// sendmail_path = "/path/to/php /path/to/mailtodisk.php" | |
// in php.ini | |
// Set the mail redirect folder path | |
const MAILTODISK_ROOT = "/opt/mailtodisk/"; | |
// Generate a date/time-based random file name | |
do { | |
$filename = 'mail_' . gmdate('Y-m-d-H-i-s') . '_' . uniqid() . '.txt'; | |
} while(is_file($filename)); | |
// Write the mail from stdin to file | |
$input = file_get_contents('php://stdin'); | |
file_put_contents(MAILTODISK_ROOT . $filename, $input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment