Forum Moderators: coopster

Message Too Old, No Replies

Mail() only working from command line

mail() only worksfrom command line

         

vishnik

5:09 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



running php 4.0.3pl1 on mandrake 7.2

the mail() function works fine if I run it from the command line (php mailtest.php) however if I load it up in my web browser it says "can't send email". I've included the code below

<?

if(mail($to,$subject,$message))
echo "<h4>sent email</h4>";
else
echo "<h4>can't send email</h4>";

?>

Any Ideas?

MattyMoose

5:57 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



(I'm assuming you're working on a *NIX system)

What do your apache log files say? Also, what does your general syslog say? Check both /var/log/messages and /var/log/maillog when you try the script both from command line and web.

manofwax

9:52 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



kinda out topic, but i still wanna know

When you modify the php.ini, what did you change?

SMTP=
path_sendmail=

i'm wondering how i can find what my SMTP is... is it in any config file?

MattyMoose

10:08 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



If you're running on a *NIX box, it will use the local SMTP/Sendmail system, which then delivers the mail by itself.

You don't need to define it outright, since PHP trusts sendmail to do its job. When you configured and installed PHP, it found where the sendmail executable is, and will use that one.

coopster

10:31 pm on Aug 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, vishnik!

running [...] on mandrake 7.2

MattyMoose said, "(I'm assuming you're working on a *NIX system).

MattyMoose, your assumption seems to be correct. hehe ;)

<edit>
OK, I apologize, I see there is a Linux for Windows which includes the fundamental functionality of Linux-MandrakeTM 7.2...seems goofy to me though -- I mean, if you're going to use Linux, use Linux. Why drop it on a Windows platform? Never mind, I don't care and I don't want this to get off topic...
</edit>

And you are also right regarding SMTP. manofwax, the SMTP configuration directive [php.net] is used under Windows only.

[edited by: coopster at 11:41 pm (utc) on Aug. 18, 2004]

manofwax

11:34 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



Thanks guys, i will try it tomorrow, and see if mail() works.

><" how come you guys know so much more than i do?
haha...

What should i do to "expand" my knowledge? hahahaha...
=)

MattyMoose

11:49 pm on Aug 18, 2004 (gmt 0)

10+ Year Member




MattyMoose, your assumption seems to be correct. hehe ;)

<edit>
OK, I apologize, I see there is a Linux for Windows which includes the fundamental functionality of Linux-MandrakeTM 7.2...seems goofy to me though -- I mean, if you're going to use Linux, use Linux. Why drop it on a Windows platform? Never mind, I don't care and I don't want this to get off topic...
</edit>

<OT>
Hay! I nevur sez I wuz smahrt or eneethingh!

That does seem pretty goofy to me too...
</OT>

coopster

12:00 am on Aug 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



manofwax,

Our PHP Library [webmasterworld.com] has some good stuff, including Learning PHP - Books, Tutorials and Online Resources
The Authoritative List
[webmasterworld.com]

And hey, welcome to WebmasterWorld.

manofwax

3:12 am on Aug 19, 2004 (gmt 0)

10+ Year Member



coopster & matty,

Millions thanks =)
May all ur wishes come true.
i will take a look at it later.
oh and i tried the mail(), it works perfectly... YAY, THANKS =)

Kev.

vishnik

1:19 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



What do your apache log files say? Also, what does your general syslog say? Check both /var/log/messages and /var/log/maillog when you try the script both from command line and web.

Thanx for pointing me in the right direction ("when in doubt view the logs").

It's a permision issue, syslog reports:

sendmail[15623]: i7JDlOt15623: SYSERR(apache): Can't create transcript file ./xfi7JDlOt15623: Permission denied
sendmail[15623]: i7JDlOt15623: SYSERR(apache): Cannot create ./dfi7JDlOt15623: Permission denied
sendmail[15623]: i7JDlOt15623: from=apache, size=0, class=0, nrcpts=0, relay=apache@localhost

how do I rectify.

MattyMoose

3:59 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Have a look at the permissions for the directory "/var/spool/mqueue"

Here's what mine shows (FreeBSD)


# ls -ld /var/spool/mqueue
drwxr-xr-x 2 root daemon 512 Aug 19 03:03 /var/spool/mqueue

What does yours show?

vishnik

4:54 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



# ls -ld /var/spool/mqueue
drwxr-xr-x 2 root mail 212992 Aug 19 12:40 /var/spool/mqueue/

I did a chmod 777 and it now works, is it safe to leave it like that or is there some alternate fix?

Thank you very much

manofwax

5:32 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



are you asking me, vishnik?

Kev.

manofwax

5:42 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



sorry, i thought you were asking

"What do your apache log files say? Also, what does your general syslog say? Check both /var/log/messages and /var/log/maillog when you try the script both from command line and web."
============================

i'm wondering how you run the mail() function from the ocmmand line. Thanks a lot.

Kev. Kev.

MattyMoose

6:55 pm on Aug 19, 2004 (gmt 0)

10+ Year Member




I did a chmod 777 and it now works, is it safe to leave it like that or is there some alternate fix?

That's not a good idea, since now any user can go in and delete/edit any users' outgoing mail.

You could probably set it to 775. Try that and see how it goes.

vishnik

7:13 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



MattyMoose,

775 doesn't work, apache needs write access which it only gets with 777. what to do?

Manofwax,

i'm wondering how you run the mail() function from the ocmmand line. Thanks a lot.

I create the php file and at the command line I simply type:

#usr/bin/php filename.php
OR
#php filename.php

MattyMoose

7:30 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



I'm wondering if it has anything to do with the old version of PHP (4.0.3) that you're using... Is it possible to upgrade to a newer version?

Also, what user are you running the script as from the command-line? root?

vishnik

8:52 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Upgrading is not an option right now, I have some issues with code NOT working on 4.2.2 that works on 4.0.3.

all that's running on this box now is web service and a backup of a pgsql DB. Would changing the owner of the mqueue break anything from root.mail to root.apache (I did that and it works) or could I do something else to put mail and apache in a group and change ownership to that group?

And yeah I run it from the command line as root

MattyMoose

8:58 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



> Upgrading is not an option right now, I have some issues with code NOT working
> on 4.2.2 that works on 4.0.3.

You can't go up to 4.3.8? :) I'd think that you should upgrade your code to work with the latest PHP, since PHP is going to continually evolve, and your code is just going to get more and more out of sync, and more and more of a nightmare when you finally move to a server that is running a later version.

> Would changing the owner of the mqueue break anything from root.mail to
> root.apache (I did that and it works)
Don't know, really... Try it for a few days and see what happens. :)

> And yeah I run it from the command line as root
That explains it working from the command line.