0

So I'm trying to do a simple test of some email functions in a PHP (Magento) application, but I'm running into an issue. All I want to do is to store the output from calls to the built-in mail() function into a local file instead of sending it through an SMTP server. I do know how and have setup SMTP access for this application in the past, but it takes some time and I figured it couldn't be that hard to do it this way anyway.

After looking at the documentation, it still seemed like it would be very straightforward since the sendmail_path configuration option seemed to be exactly what I needed. I verified that both on the command line and via Apache, the php.ini configuration file being loaded is the same one, so I edited that file and set sendmail_path to /usr/local/bin/testsendmail. I then created a new script at that path that takes the input and writes it to /tmp/sent-mail.html. I created that file and made sure it has 777 permissions just to make sure I didn't run into permissions errors (the testsendmail script also had 775 permissions for the same reason).

In order to send email from a web page, I created a simple test PHP script that does nothing but make a call to mail() using some test data. When I run this script via php /var/www/html/test/test.php, it runs exactly as I'd expect: it calls out to the testsendmail file which then writes the email to the file I specified. However, when I open this URL in the browser, the mail() function returns true but does nothing else.

I enabled all the normal error logging options, I don't get anything back with those. It does continue running after the mail() call, so it's not silently erroring. I made sure all of the files in question had open permissions so there was no chance of a permissions error. The only thing I can think of is that maybe Apache spawns a new process to send the mail, and for some reason this process isn't allowed to modify files or something? I'm really not sure, so any help would be greatly appreciated. I can send the exact contents of the test scripts, but they really don't have anything other than the calls to mail() and file_put_contents() to write out the data.

  • I'm seeing the same thing - via command line script works, via apache php-fpm, script does not run. If the binary sendmail is used, then it does work. This used to work, so it feels like a recent update broke php-fpm's ability to call a script. – user1279887 Sep 20 '22 at 13:46

0 Answers0