Fake Sendmail for Mac (linux)

When developing in PHP perhaps you need to set up a sendmail that just outputs things to text. No need to setup delivery via SMTP. Just create an executable ruby script somewhere, for example: /usr/bin/fake-sendmail.sh with following content:

$ touch /usr/bin/fake-sendmail.sh

# make it executable (will require root priv.)
$ chmod +x /usr/bin/fake-sendmail.sh
#!/usr/bin/ruby
path = "/tmp/fake-mailer"
Dir.mkdir(path) if !File.exists?(path)
File.open("#{path}/#{Time.now.to_i}.txt", "w") do |f|
    f.puts ARGV.inspect
    $stdin.each_line { |line| f.puts line }
end

Then edit php.ini
sendmail_path = /usr/bin/fake-sendmail.sh

props to dan for the script

Update

I changed one line to use a micro-time format because I was having some trouble with a very fast sending script overwriting some of the existing e-mail files. So, here is the new line to insert:

File.open("#{path}/#{(Time.now.to_f.to_s.gsub(".","")+'00000000')[0..14]}.eml", "w") do |f|

Do you need fake sendmail for windows? Check out Byron’s fake sendmail for windows.

Related Posts:

  • No Related Posts
This entry was posted in Tech Tips, Web Development and tagged , , , , . Bookmark the permalink.

One Response to Fake Sendmail for Mac (linux)

  1. nofx says:

    fake-sendmail.php

    !/usr/bin/php -q

    <?php $emails = file_get_contents(‘php://stdin’); $emails = str_replace(“\r”, ”, $emails); $emails = str_replace(“\n”, ‘|’, $emails); $emails = str_replace(‘To: ‘, “\nTo: “, $emails); file_put_contents(‘/path/emails.txt’, $emails, FILE_APPEND);

Leave a Reply

Your email address will not be published. Required fields are marked *