LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   mail function under Apache/PHP5 (https://www.linuxquestions.org/questions/linux-networking-3/mail-function-under-apache-php5-515217/)

pwabrahams 12-31-2006 04:05 PM

mail function under Apache/PHP5
 
I'm running Opensuse Linux 10.2. I have a web page containing the PHP code

echo mail("abrahams@acm.org","test php mail","test with an echo");

When I look at the web page in Firefox (I assume the browser doesn't matter, though), this line turns into "1", indicating that the mail function succeeded. I could not find any error messages anywhere, including the system log. But nonetheless, I received no mail.

How can I track this down?

rylan76 01-01-2007 02:14 AM

This can be tricky, but first, are you 100% sure your mail setup is correctly configured on that system?

Are you trying to localmail yourself, or do you expect the system to go out over a mail relay through the internet and then get through to you?

If you run phpinfo() on that machine, what does it have under

sendmail_path

and the "Standard" section? What does

Path to sendmail

have set for it?

Also, what is the content of the

SMTP

and

smtp_port

lines in the phpinfo screen?

j-ray 01-01-2007 11:14 AM

if sendmail is installed correctly on your system - it may be that the pop server does not accept emails from your local box because it cant resolve your ip or whatever reason...

pwabrahams 01-01-2007 11:51 AM

> This can be tricky, but first, are you 100% sure your mail setup is correctly configured on that system?

The command

mail abrahams@acm.org -s test
this is a test
^D

works as it should and I get the message.

> Are you trying to localmail yourself, or do you expect the system to go out over a mail relay through the internet and then get through to you?

> The latter.

> If you run phpinfo() on that machine, what does it have under sendmail_path

The default: "/usr/sbin/sendmail -t -i". And /usr/bin/sendmail exists and is executable by all.

> and the "Standard" section? What does Path to sendmail have set for it?

Same as above: /usr/sbin/sendmail -t -i

> Also, what is the content of the SMTP and smtp_port lines in the phpinfo screen?

SMTP: localhost
smtp_port: 25

Does this info help?

pwabrahams 01-01-2007 11:56 AM

Quote:

Originally Posted by j-ray
if sendmail is installed correctly on your system - it may be that the pop server does not accept emails from your local box because it cant resolve your ip or whatever reason...

If the problem is with the POP server, how could I determine that?

pwabrahams 01-01-2007 12:01 PM

Sendmail problem
 
I just tried

/usr/sbin/sendmail abrahams@acm.org
this is the message.
^D

and nothing was received.

So how do I convince sendmail to send this message the same way that mail does?

rylan76 01-01-2007 04:21 PM

Quote:

Originally Posted by pwabrahams
I just tried

/usr/sbin/sendmail abrahams@acm.org
this is the message.
^D

and nothing was received.

So how do I convince sendmail to send this message the same way that mail does?

Hmm - I guess it might behave like this because mail calls sendmail through its queueing process (as far as I know) ?? You should have two sendmail process running, one is sendmail itself, one is the sendmail queue process. I'm guessing mail calls this queueing process in the "right" way to get sendmail to send out the mail correctly. Further guess might be that it prepends some form of routing information?

From what you replied to the results in phpinfo() it seems your PHP setup is 100% fine, and your problems does not lie there...

You might need to altery sendmail.cf (the sendmail sending / routing rules) to enable sendmail to work "directly". No idea how or what you will need to do though - PHP seems fine, and thats basically where my experience so far stops...

pwabrahams 01-01-2007 08:11 PM

Additional parameters
 
I think I know now what the problem is, by looking at my .mailrc file:

set from=abrahams@acm.org
set smtp=smtp.comcast.net
set smtp-auth-user=pwabrahams
set smtp-auth-password=xxx

Somehow I need to transmit the information in these lines to php. How can I do that? I'd guess it requires adding something to php.ini, which brings up another question: which copy of php.ini is the active one? I'm guessing it's /etc/php5/apache2/php.ini, but I'm not sure.

I thought I might be able to do it by adding parameters to the sendmail call, but I can't find any sendmail parameters that carry this information.

rylan76 01-02-2007 12:27 AM

Hmm - I'm not sure but can't you add these in the "headers" that you send to the PHP mail() call? Although I'm not sure those types of parameters can be passed in the headers section of the mail() call, it does seem the best bet?

pwabrahams 01-02-2007 11:49 AM

I'm no expert on this, but it seems that the headers carry information pertaining to the message, not the agents that handle it. I haven't found any way to put the ISP username/password information there.

I'm now investigating another path: setting up parameters to the SASL authenticator. There's some googlable stuff about it on the Web. But looking into it is drawing me into obscure corners of networking under Linux that I was hoping I would not have to deal with.

j-ray 01-02-2007 02:04 PM

as far as i know php on windows is usually cofigured to work with an external smtp server and on unix systems to work with internal sendmail. info regarding the smtp server does not belong to the mail headers.
take a look at php.net -> type "mail" into search box

pwabrahams 01-09-2007 04:30 PM

Here is the answer
 
I've solved this problem:), thanks in part to the fine advice that I found here:http://postfix.state-of-mind.de/patr...ilservers.html

Very briefly, here's the method given there (assuming that "sendmail" is a wrapper for postfix):

1. Assume the ISP access URL, username, and password are "smtp.isp.com", "uname", and "pwd". Append the line
Code:

smtp.isp.com  uname:pwd
to the file /etc/postfix/sasl_passwd.

2. Create the file /etc/postfix/sasl_passwd.db with the command
Code:

postmap hash:/etc/postfix/sasl_passwd
3. Insert the lines
Code:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =

4. Reload postfix with
Code:

postfix reload
There's one more essential step for getting the mail command to work that does not involve postfix. In your php5.conf file, insert the line

Code:

sendmail_path = sendmail -t -i -f myaddr@myisp.net
Without this, the mail relay at your ISP will almost certainly attempt to send an acknowledgment,
which will bounce and cause your mail not to be sent.


All times are GMT -5. The time now is 08:44 PM.