Skip to content

Instantly share code, notes, and snippets.

@Tobur
Created July 19, 2013 08:34

Revisions

  1. Alexandr created this gist Jul 19, 2013.
    61 changes: 61 additions & 0 deletions fake send mail
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    <?php
    //insert into php.ini
    //sendmail_path = "/usr/local/bin/php /localetc/sendmail_stub/fake.php"

    $sendMailStubObj = new SendMailStub();
    $sendMailStubObj->main();

    class SendMailStub
    {
    private $_saveEmailsPath = "/home/tobur/mail/";

    function main()
    {
    //--- get email from the stream ---//
    $stream_data = '';
    $stream_handler = fopen('php://stdin', 'r');
    while ($t = fread($stream_handler, 2048)) {
    if ($t === chr(0))
    break;
    $stream_data .= $t;
    }
    fclose($stream_handler);

    //save to file
    $fwrite_handler = fopen($this->_generateUniquePath(), 'w');
    fwrite($fwrite_handler, $stream_data);
    fclose($fwrite_handler);
    }

    private function _generateUniquePath()
    {
    $i = 0;
    do {
    $path = $this->_saveEmailsPath . $this->_generateFname($i);
    $i++;

    if($i > 100){
    break;
    }
    } while (file_exists($path) == true);

    return $path;
    }

    private function _generateFname($i = 0)
    {
    $parts = array(
    date('Y-m-d_H-i-s'),
    );

    if ($i > 0) {
    $parts[] = "_{$i}";
    }
    $parts[] = ".eml";

    $fname = implode("", $parts);

    return $fname;
    }
    }