# Apache webserver: Function mail() in PHP [SOLVED]

## dimi3

Hi!

The mail() function in PHP doesn't work.

I don't understand why.

Can you help me?

ThanksLast edited by dimi3 on Fri Dec 23, 2005 2:27 pm; edited 1 time in total

----------

## steveb

If you have PHP runing in "Safe mode", then probably your mail() command in PHP will not work.

cheers

SteveB

----------

## dimi3

thank you for your answer!

Is "Safe Mode" configuration in php.ini ?

----------

## steveb

 *dimi3 wrote:*   

> thank you for your answer!
> 
> Is "Safe Mode" configuration in php.ini ?

 

Yes. Search for "safe_mode".

cheers

SteveB

----------

## dimi3

thank you!

I turned safe_mode to "Off". But it still doesn't work  :Sad: 

I also explicitly specify the "sendmail_path" to "/usr/lib/sendmail"   ----> no success

Any other idea?

----------

## hanj

I haven't noticed any problems with mail() w/safe_mode, but I have experienced problems when apache is chroot'd. I think you're problem is the path.

Try adding just 'sendmail' in the sendmail_path.. no path.

```
sendmail_path = "sendmail -t -i"
```

HTH

hanji

----------

## dimi3

i will try thank you!

----------

## dimi3

It still doesn't work  :Sad: 

I have the following configuration:

safe_mode = Off

...

sendmail_path = sendmail -t -i

any idea?

----------

## hanj

Try with quotes...

```
sendmail_path = "sendmail -t -i"
```

I'm wondering if you might have a configuration error higher up in the ini.

hanji

----------

## dimi3

thank you for your answer.

unfortunately, i already tried with quotes "sendmail -t -i".

any other idea?

would be great!

----------

## dimi3

Hi! 

I set up a webserver but the mail() function (PHP) doesn't work...

Sending a mail like this works:

```

mail -s "test" <myemailaddr@domain.com>

```

Any idea?

thanks!

----------

## hanj

Try starting apache with strace, then execute your mail script. Output of the strace should be sent to a file, then grep the file for sendmail. Look for anything weird. Might be a clue in there.

```
/etc/init.d/apache2 stop

strace -o mytrace -fF apache2 -D DEFAULT_VHOST -D SSL -D SSL_DEFAULT_VHOST -D PHP4
```

execute your mail script

```
killall strace

killall apache2

/etc/init.d/apache2 start

vi mytrace
```

hanji

----------

## dimi3

thanks for your help!

but im not sure if there are indications of the error.

I executed what you proposed and i "grep-ped" it.

Here is the result:

```

grep "test_mail.php" mytrace | less

9594  read(13, "GET /tests/test_mail.php HTTP/1."..., 8000) = 415

9594  stat64("/var/www/localhost/htdocs/tests/test_mail.php",

{st_mode=S_IFREG|0755, st_size=122, ...}) = 0

9594  lstat64("/var/www/localhost/htdocs/tests/test_mail.php",

{st_mode=S_IFREG|0755, st_size=122, ...}) = 0

9594  lstat64("/var/www/localhost/htdocs/tests/test_mail.php",

{st_mode=S_IFREG|0755, st_size=122, ...}) = 0

9594  open("/var/www/localhost/htdocs/tests/test_mail.php", O_RDONLY) = 14

```

----------

## dimi3

On my webserver, the file /etc/php/apache2-php4/php.ini is configured like this:

```

...

safe_mode = Off

...

sendmail_path="/usr/sbin/ssmtp -t -i"

...

```

I don't need a complete MTA, I only need to send mails with PHP.

The file /etc/ssmtp/ssmtp.conf is configured like this:

```

root=<my.email@address.com>

mailhub=smtp.isp.com

rewriteDomain=domain.com

```

On the webserver, the following command works perfectly:

```

mail -s "sujbect" <my.email@address.com>

```

BUT, a PHP script using the PHP mail() function doesn't work!

I really need help! It would be great! I'm on it for 2 days  :Sad: 

----------

## hanj

Hello

You should grep the file for 'sendmail'.. not your script name. I just want to make sure that apache can deal with sendmail. For instance, when I ran my test mail script.. and grep for send mail.. I see this.

```
28104 stat64("/usr/local/sbin/sendmail", 0xbfcb2df0) = -1 ENOENT (No such file or directory)

28104 stat64("/usr/local/bin/sendmail", 0xbfcb2df0) = -1 ENOENT (No such file or directory)

28104 stat64("/usr/sbin/sendmail", {st_mode=S_IFREG|0755, st_size=157004, ...}) = 0

28104 stat64("/usr/sbin/sendmail", {st_mode=S_IFREG|0755, st_size=157004, ...}) = 0

28104 rt_sigaction(SIGINT, {SIG_DFL}, {SIG_DFL}, 8) = 0

28104 rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_IGN}, 8) = 0

28104 rt_sigaction(SIGCHLD, {SIG_DFL}, {0x8080e0a, [], 0}, 8) = 0

28104 execve("/usr/sbin/sendmail", ["sendmail", "-t", "-i", "-F", "test@comp.com", "-f", "test@comp.com"], [/* 40 vars */]) = 0

28097 write(19, "To: hanji@test.com\nSub"..., 124) = 124

28097 close(19)                         = 0

28097 waitpid(28110,  <unfinished ...>

28110 getpid()                          = 28110

28110 close(19)                         = 0

28110 dup2(18, 0)                       = 0

28110 close(18)                         = 0

28110 getpid()                          = 28110

28110 rt_sigaction(SIGRTMIN, {SIG_DFL}, NULL, 8) = 0

28110 rt_sigaction(SIGRT_1, {SIG_DFL}, NULL, 8) = 0

28110 rt_sigaction(SIGRT_2, {SIG_DFL}, NULL, 8) = 0

28110 execve("/bin/sh", ["sh", "-c", "sendmail -t -i -F test@comp"...], [/* 41 vars */]) = 0
```

Also.. is your apache in a chroot?

Thanks!

hanji

----------

## pjp

Please do not create multiple threads on the same topic.  Thanks.

----------

## dimi3

@hanji

Thank you very much, I will do that right now and post the results

----------

## dimi3

@pjp

Sorry, I will not do that again.

----------

## dimi3

@hanji

I "re-strace" again...

I have "grep-ed" the file for "sendmail", there was nothing...

Then I "grep-ed" the file for "ssmtp":

```

# grep "ssmtp" mytrace | less

5469  execve("/bin/sh", ["sh", "-c", "/usr/bin/ssmtp -t -i"], [/* 24

vars */]) = 0

5469  execve("/usr/bin/ssmtp", ["/usr/bin/ssmtp", "-t", "-i"], [/* 24 vars */])

= -1 ENOENT (No such file or directory)

5469  stat64("/usr/bin/ssmtp", 0xbf85d79c) = -1 ENOENT (No such file

or directory)

5469  stat64("/usr/bin/ssmtp", 0xbf85d6dc) = -1 ENOENT (No such file

or directory)

5469  write(2, "sh: /usr/bin/ssmtp: No such file"..., 46) = 46

```

Thanks a lot!

----------

## magic919

So is it /usr/bin/ssmtp or /usr/sbin/ssmtp?  Looks like your earlier quote conflicts with the path PHP is looking for.

----------

## dimi3

oooHH... Thank you very much!

This solves the problem! 

In conclusion: 

In php.ini, if you want to send mails with ssmtp, the sendmail_path should be:

```

sendmail_path="/usr/sbin/ssmtp -t -i"

```

I wish you all a merry xmas and a happy new year!

----------

