Page 1 of 2

[SOLVED] sendmail problems

Posted: Wed Jan 03, 2007 6:44 pm
by mpuha
Hello,

New to the foum so if i'm in the wrong section i'm sorry.

I'm currently running FedoraCore 6 w/apache php 5....

My problem is very wierd. I wrote a e-mail script (aaa.php) that when I run it from the command line like so

root@localhost# php aaa.php

it works fine

but when i access it from the browser

https://mydomain.com/aaa.php

nothin happens.

no errors in /var/mail/root or the error log i specify in the code.
no traffic recorded in wireshark relvant to scipt

can any one enlighten me, If you need a log or config let me know

Posted: Wed Jan 03, 2007 7:14 pm
by feyd
Permission problem with Apache being able to execute the command(s)? Maybe a configuration problem where PHP (under Apache) doesn't know the same things as the CLI run one?

At some point it may help to post your code, although I don't know if that's right now...

Posted: Wed Jan 03, 2007 7:19 pm
by mpuha
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

        $message = 'A new blah<br>blah # <br>By:  From ';
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: cgit@mycompany.com\n";
        $sentTo = "mp@theircompany.com";
        if (mail($sentTo, 'Test ISA6', $message, $headers))
        {
            echo "An e-mail was sent to $sentTo";
        } else {
          echo "Not Sent to: $sentTo";
        }

// Make sure that the log_errors and error_log directives are set
// in the php.ini file. They must be set for the error_log function 
// to be able to write errors to the PHP error log.

// If they're not set, you can set them at runtime by
// uncommenting the two lines below.
ini_set ('log_errors', 1);
ini_set ('error_log', 'syslog');

// You can also specify a file for the error log directive.
ini_set ('error_log', '/var/log/php_error.log');        

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 03, 2007 7:35 pm
by feyd
You're making sure logging is on after the code has been run?

Posted: Wed Jan 03, 2007 7:46 pm
by mpuha
no its on in the php.ini that was something from earlier i got rid of... how do i check those permisions you mentioned above?

Posted: Wed Jan 03, 2007 9:09 pm
by feyd
It may be good to run phpinfo() to check where php.ini is being loaded from for both the CLI and Apache run versions.

If they are the same then the unix command ps can often be used to find out which user Apache is running as; probably "nobody" or "www." You can then use "which" or "locate" followed by an "ls" to determine the user and group to which sendmail belongs.

Alternately you could send the mail through an SMTP server using a library such as Swift.

Posted: Thu Jan 04, 2007 8:30 am
by mpuha
Thanks for your help.

Posted: Thu Jan 04, 2007 10:43 am
by feyd
I didn't really need to see it. ;)

It was for you to see where your php.ini is being loaded from (/etc/php.ini) through Apache. Did you do the same through the CLI?

Also of note is the sendmail_path directive. /usr/sbin/sendmail is listed, is this correct, in both environments?

Posted: Thu Jan 04, 2007 11:51 am
by Chris Corbyn
If you're using mail() you'll want to set a value from sendmail_from in php.ini, even if you plan on overwriting it with a From: header. You can just use ini_set() for this.

Posted: Sat Jan 06, 2007 12:19 pm
by mpuha
feyd,

I cannot find the CLI config file... but that is the correct path for sendmail...
I did config from in sendmail section. still not working

Posted: Sat Jan 06, 2007 9:34 pm
by Chris Corbyn
mpuha wrote:feyd,

I cannot find the CLI config file... but that is the correct path for sendmail...
I did config from in sendmail section. still not working
Perhaps PHP when running under apache is using a userid which sendmail is rejecting (e.g. "nobody"). When you run with CLI you run as the user who starts the script.

EDIT | I should point out that it is quite common to block the use of sendmail to nobody.

Posted: Sat Jan 06, 2007 9:55 pm
by feyd
d11wtq wrote:Perhaps PHP when running under apache is using a userid which sendmail is rejecting (e.g. "nobody"). When you run with CLI you run as the user who starts the script.

EDIT | I should point out that it is quite common to block the use of sendmail to nobody.
That's where my line of posts is/was leading...

Posted: Sun Jan 07, 2007 1:47 am
by mpuha
so i should try changing userid on apche user and group...

also i tried swift... which i have to say id great. running in to the same problem command line works fine but when i try it througha bowser i get the following error

Code: Select all

The mailer failed to send the mail. Errors:

Array
(
    [0] => Array
        (
            [num] => 0
            [time] => 0.76166000 1168155652
            [message] => Connection to the given MTA failed. The Connection Interface said: Permission denied
        )

    [1] => Array
        (
            [num] => 0
            [time] => 0.76467000 1168155652
            [message] => The MTA doesn't support any of Swift's loaded authentication mechanisms
        )

)


Log:

Array
(
)
I'm so mind f@#ked right now trying to get this to work... sorry for being such a newb
and thanx for all your time guys

Posted: Tue May 29, 2007 6:15 pm
by rabw
I'm getting the same problem
The mailer failed to connect. Errors:

Array
(
[0] => Array
(
[num] => 0
[time] => 0.31936800 1180478549
[message] => Connection to the given MTA failed. The Connection Interface said: Permission denied
)

)


Log:

Array
(
)
This is using the Wordpress plugin on FC6/Apache/PHP5.
Literally been trying to solve it for a week and cannot find anything that has solved it.

Does anyone have any ideas or am I stuffed? I CAN connect to the SMTP server via telnet (smtp.googlemail.com).

Posted: Wed May 30, 2007 2:13 am
by Chris Corbyn
It's either a permissions problem, or a firewall rule. Also, when you connect via telnet are you doing it *from* the same server? I've had a lot of people try connecting from home rather than from their web host.

That's old code too. I'm pretty sure the wordpress plugin author released a version which uses Swift 3. I could be wrong though.