Score:0

I've set sendmail_path in PHP.ini, and it works fine on the command line, but not when the same script is called from an Apache server?

cn flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.