sj26 / mailcatcher

Catches mail and serves it through a dream.
http://mailcatcher.me
MIT License
6.31k stars 578 forks source link

php sendmail (not using / failing with) mailcatcher #132

Closed Zauberfisch closed 10 years ago

Zauberfisch commented 10 years ago

I am trying to setup php to use mailcatcher in my dev/test environment. However am facing a odd problem.

I solely work in virtual machines, and have managed to get it working in one. Unfortunately, the one it is working in is dirty and not reproduce able, as I have tested other mail catching alternatives before mailcatcher.

After I got it working in that test VM, I tried to apply it to my base box. But in the base box, php is not using mailcatcher.

Base box specs:

installation of mailcatcher:

gem install mailcatcher creates=/usr/bin/mailcatcher
sed -ir "s@;\?sendmail_path =.*@sendmail_path = \"/usr/bin/env $(which mailcatcher) -f local\@host\"@" /etc/php5/apache2/php.ini
sed -ir "s@;\?mail.log =.*@mail.log = \"/vagrant/logs/mail/mail.log\"@" /etc/php5/apache2/php.ini
pkill mailcatcher
mailcatcher --ip=0.0.0.0 

I have confirmed that mailcatcher is running and working (I can speak smtp with it using telnet, and the mails show up in the gui)

Because it is working in the dirty VM, I am assuming mailcatcher is missing some dependency in the clean VM that I have previously installed with some other package (eg postfix) on the dirty VM. Or perhaps I am just to tired and missing something obvious?


after some playing around I have also tried sending mails via cli, and am now getting the following error messages on the clean VM (works in dirty):

vagrant@precise32:~$ sudo php -r "mail('foo@bar.com', 'Subject', '<strong>test</strong>', null, '-fwebmaster@example.com');"
/opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1450:in `complete': invalid option: -webmaster@example.com (OptionParser::InvalidOption)
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1448:in `catch'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1448:in `complete'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1287:in `parse_in_order'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1254:in `catch'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1254:in `parse_in_order'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1248:in `order!'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1339:in `permute!'
    from /opt/vagrant_ruby/lib/ruby/1.8/optparse.rb:1360:in `parse!'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/mailcatcher-0.5.12/lib/mail_catcher.rb:62:in `parse!'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/mailcatcher-0.5.12/lib/mail_catcher.rb:61:in `tap'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/mailcatcher-0.5.12/lib/mail_catcher.rb:61:in `parse!'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/mailcatcher-0.5.12/lib/mail_catcher.rb:127:in `run!'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/mailcatcher-0.5.12/bin/mailcatcher:4
    from /opt/vagrant_ruby/bin/mailcatcher:19:in `load'
    from /opt/vagrant_ruby/bin/mailcatcher:19

and:

vagrant@precise32:~$ sudo php -r "mail('foo@bar.com', 'Subject 2', '<strong>test</strong>');"
Starting MailCatcher
~~> ERROR: Something's using port 1025. Are you already running MailCatcher?
sj26 commented 10 years ago
sed -ir "s@;\?sendmail_path =.*@sendmail_path = \"/usr/bin/env $(which mailcatcher) -f local\@host\"@" /etc/php5/apache2/php.ini

should be

sed -ir "s@;\?sendmail_path =.*@sendmail_path = \"/usr/bin/env $(which catchmail) -f local\@host\"@" /etc/php5/apache2/php.ini
Zauberfisch commented 10 years ago

facepalm oh god ...

thanks for the fast response.

sj26 commented 10 years ago

No worries, hope it's working for you. :-)

Zauberfisch commented 10 years ago

working perfectly and making my life a lot easier - love it.

mykec commented 5 years ago

I mistakenly added "sendmail_path=/usr/local/bin/mailcatcher" to my "mailcatcher.ini" module file for PHP... and got the exact same troubling issue until I found this page... Changing it to "catchmail" was all it needed. D'oh! LOL Thanks for blazing my trail. :)