6

i will try to describe my problem:

to debug outgoing email in local environment i installed mailcatcher (http://mailcatcher.me/) but faced some problems with catching mails sent from web. if i run the script which contains only one mail() call, everything is fine and i can see the sent email in mailcatcher 127.0.0.1:1080. But when i try to access the same script from the web browser, the mail() function returns false, no any error displayed in browser, nothing in error logs. In mail log even i can see the call for mail() function.

i am not sure, may be my nginx/php-fpm configuration is wrong, or something wrong with permissions.

selinux is disabled.

please help if you know the solution.

Thanks in advance

user1112057
  • 180
  • 3
  • 11
  • how are you running your test script manually? command line? note that PHP usually has TWO .ini files: command line + web-server embedded. If you configured mailcatcher in the CLI .ini file, then it won't work when you're running via webserver (SAPI mode). – Marc B Jul 14 '14 at 16:54
  • i wrote, i run both ways, in command line it works, from the web does not. with php.ini everything is fine, the at least the phpinfo() call get me the following for both cases: sendmail_path /usr/bin/env catchmail – user1112057 Jul 15 '14 at 08:21
  • I am having exactly the same problem. Did you manage to find a solution? – Gadelkareem Mar 05 '15 at 23:58

4 Answers4

8

I faced the same problem on ubuntu 14.04.

/etc/php5/cli/php.ini and /etc/php5/fpm/php.ini had the same sendmail_path configuration but only php-cli could send emails.

For my environment, Mailcatcher works on a distant server and I use the catchmail command to contact it.

Here is the sendmail_path I used:

sendmail_path = /usr/bin/env catchmail --smtp-ip mailcatcher-ip -f address@example.com

For the fpm php.ini file, I had to specify the full path to catchmail for the mail function to work correctly:

sendmail_path = /usr/bin/env /usr/local/bin/catchmail --smtp-ip mailcatcher -f address@example.com
Alexis N-o
  • 3,954
  • 26
  • 34
  • 1
    Did you change something with permissions because even with full path PHP-FPM is not able to run catchmail still! – Gadelkareem Mar 05 '15 at 23:59
3

If you use Mac OS Sierra or later:
here is the right place of catchmail:

change sendmail_path = /usr/bin/env catchmail -f catcher@mailcatcher.me
By sendmail_path = /usr/local/bin/catchmail -f someone@domain.com.

berramou
  • 1,099
  • 9
  • 11
2

With php-fpm it works neat with the supplied wrapper script of RVM(?).

sendmail_path = /usr/local/rvm/wrappers/default/catchmail
Emii Khaos
  • 9,983
  • 3
  • 34
  • 57
  • When our hosting company updated PHP from 5.3.3 to 5.4.40 the "/usr/bin/env /usr/local/bin/catchmail" no longer worked. The wrapper solution fixed it. – Onshop Apr 28 '15 at 19:44
0

On CentOS 7 using PHP-FPM with PHP 5.6, I found that I had to modify /etc/php-fpm.d/www.conf instead of adding ini files into /etc/php.d or modifying /etc/php.ini. This also required the full path as in @Alexis N-o's answer.

php_admin_value[sendmail_path] = '/usr/bin/env GEM_PATH=/usr/share/gems:/usr/local/share/gems:/usr/share/rubygems:$HOME/.gem/ruby /usr/local/bin/catchmail --smtp-ip 127.0.0.1 --smtp-port 1025 -f mailcatcher@example.com'

Update: more recently I found that GEM_PATH is nil when running php-fpm as apache on some environments. No matter what I tried (/etc/gemrc) I couldn't do it other than to inject GEM_PATH as part of this command.

mradcliffe
  • 137
  • 2
  • 10