Question

I have a simple test.php file which says:

if (mail('my-real-address@gmail.com', 'test mail', 'test mail test')){
echo 'ok';
}
else{
echo 'bad';
}

When I execute this file in CLI with php5 -f test.php, the file's output is ok, I receive the e-mail properly and /var/log/mail.log gets lines written to it.

However, when I execute this file from apache2's virtualhost (from web, by loading it), it also says ok, but no log is created and I don't receive the e-mail (it's not in the SPAM folder either).

Any idea what may I be doing wrong?

One idea that comes to my mind is that in CLI I'm executing it as user X, while in virtualhost I believe I'm executing it as www-data user. However, I don't know where to check if there is any such limitation to postfix.

Any ideas?

EDIT

I tested it as www-data in CLI and it does work for this user in CLI.

sudo su www-data
php5 -f test.php
Was it helpful?

Solution

Did you check your php.ini?

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

http://www.quackit.com/php/tutorial/php_mail_configuration.cfm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top