Puphpet: MailHog doesn't catch emails sent by PHP

Created on 9 Dec 2015  路  3Comments  路  Source: puphpet/puphpet

$ php -r "mail('[email protected]', 'test', 'test');"
2015/12/09 16:44:17 Using in-memory storage
2015/12/09 16:44:17 [SMTP] Binding to address: 0.0.0.0:1025
2015/12/09 16:44:17 [SMTP] Error listening on socket: listen tcp 0.0.0.0:1025: bind: address already in use

Fixed this by installing ssmtp and updating /etc/php5/cli/conf.d/zzzz_custom.ini to:
;sendmail_path='/usr/local/bin/mailhog'
sendmail_path='/usr/sbin/ssmtp -t'

/etc/ssmtp/ssmtp.conf:
...
mailhub=localhost:1025
...

Possibly there are better ways but this one worked for me.

My config.yml:
http://pastebin.com/jGqghAqF

Most helpful comment

;sendmail_path='/usr/local/bin/mailhog'

You actually want this to be

sendmail_path='/usr/local/bin/mailhog sendmail [email protected]'

See: https://github.com/puphpet/puphpet/blob/master/archive/puphpet/puppet/manifests/Php.pp#L204

All 3 comments

;sendmail_path='/usr/local/bin/mailhog'

You actually want this to be

sendmail_path='/usr/local/bin/mailhog sendmail [email protected]'

See: https://github.com/puphpet/puphpet/blob/master/archive/puphpet/puppet/manifests/Php.pp#L204

FYI for others looking for why MailHog may not be catching Php SMTP emails.

check your ports! if you are using a Mail::factory or other class for SMTP emails, then it may default to port 25. MailHog configuration defaults to port 1025.

@Artistan thanks.

basically:

  1. standard puphpet setup (mid 2017)
  2. vagrant ssh; sudo apt-get install postfix; confirm all defaults (use tab/arrows, enter to navigate)
  3. set your app's smtp port to 1025 for local testing
  4. send a mail via some form or other means that will go via smtp/sendmail 1025
  5. yourlocaldomain.dev:1025

I am used to CakePHP3 (where things are a bit easier to decipher) and this way I could test Zend Framework sendmail contact forms.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex-kusakin picture alex-kusakin  路  5Comments

meglio picture meglio  路  4Comments

bickerstoff picture bickerstoff  路  4Comments

richdynamix picture richdynamix  路  5Comments

gkatsanos picture gkatsanos  路  6Comments