Page 1 of 1

mail function woes...

Posted: Mon Jun 11, 2007 4:28 pm
by TreyAU21
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]


I'm not a Linux guru, but I can get around.  I'm having problems getting the mail() function to work for me on this one server.  It's at work and therefore behind some sort of a firewall (not sure if that has any anything to do with this problem).  As far as the local box is concerned, I have disabled it's firewall, etc.

The box has Fedora Core 6 installed (with PHP 5.1.6).  Here is the code.  I have verified that this works on a different server of mine outside of this network.  Here is the code:

[b]index.php[/b] - An HTML form that asks the user to specify an email address.
[syntax="html"]
<html>
<head>
        <title>This is an email test...</title>
</head>
<body>
<form action="./email_test.php" method="post">
Email Address: <input type="text" name="email" maxlength="64"> <input
type="submit" value="Send" name="email_send">
</form>
</body>
</html>
email_test.php - Gets the information from the form and attempts to send an email to that address. If it fails it throws up an error message (which I get everytime on this server)[/syntax]

Code: Select all

<?php

$email = $_POST['email'];

$to      = $_POST['email'];
$subject = 'Testing... 1... 2... 3';
$message = 'This is a test from the GTK-DEV server.  If you did NOT
recieve this email please send xxx@yyy.com a response. ';
$headers = 'From: xxx@yyy.com' . "\r\n" .
    'Reply-To: xxx@yyy.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$retVal = mail($to, $subject, $message, $headers);

if($retVal) {
        echo "Your email message was sent successfully!!!<br><br>";
} else {
        echo "ERROR: Your email message was NOT sent!!!<br><br>";
        echo "  <b>Email</b>:   " . $to . "<br>";
        echo "  <b>Title</b>:   " . $subject . "<br>";
        echo "  <b>Message</b>: " . $message;
}

?>
Here's what I get on return:

Code: Select all

ERROR: Your email message was NOT sent!!!

Email: someone@gmail.com
Title: Testing... 1... 2... 3
Message: This is a test from the GTK-DEV server. If you did NOT recieve this email please send xxx@yyy.com a response.

Are there any ideas on what could be causing this. Are there certain PHP packages that I should make sure are installed, or any configuration in php.ini that I can alter. I just wish I had better error messages to debug this... are there other ways to test this functionality to determine the root of the problem?

Thanks for your help,
Trey


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: Mon Jun 11, 2007 5:19 pm
by RobertGonzalez
You may want to try Swiftmailer, as it has very good reporting features for things not working.

Other than that, I would say start out small and just run a simple test mail page with no variable or nothing that could scum it up. Basically something like:

Code: Select all

<?php
if (!mail('me@myaddres.com', 'Test Mail', 'This is a test'))
{
  echo 'Freaking Crap!';
}
else
{
  echo 'Sweet daddy I got it going!';
}
?>

Posted: Mon Jun 11, 2007 6:04 pm
by TreyAU21
Yeah... I certainly get 'Freaking Crap' from your example. :D

I've used mail() on several occasions, and I'm certainly familiar with it's operation. I think this is more of a server setup issue, which is certainly not my forte (and I know it's not necessarily the purpose of these forums, but I was hoping someone might have experienced this). I'll try to set up Swiftmail, and in doing so, could you direct me to some links that would assist in Swiftmail debugging of this issue.

I am SOOO in a time crunch (as is always the case), so I'm panicking trying to get this server up to snuff because the application that I'm working on requires email notification functionality.

On a side note, I set up a phpbb install on this server, and it was throwing errors left and right when emailing from within the app. That was my first encounter with the issue, which led me to further test and debug. That all left me nowhere. (Also, I apologize for the script above being in such a state, but it's been through several changes... you know how debugging can make code ugly in a hurry).

Any further help would be greatly appreciated.

Trey

Posted: Mon Jun 11, 2007 7:04 pm
by RobertGonzalez
It may be the mailing application your server is using. What is it?

Posted: Mon Jun 11, 2007 7:38 pm
by TreyAU21
Everah wrote:It may be the mailing application your server is using. What is it?
sendmail. It is installed and is working (at least partially). I have installed the pine package, and when I use pine (which is a command line mailing client) I am able to successfully send an email using its interface. I don't know too awfully much about sendmail configuration, but usually I let the distribution installation program install the sendmail package and configure it... it usually does it correctly.

Posted: Mon Jun 11, 2007 8:10 pm
by RobertGonzalez
Maybe check to see that the mailserver is running. That is about as far as my knowledge of mail goes. Sorry, but I know that there are many more knowledgable people coming on tonight that could help out a lot more than me when it comes to mail.

Posted: Mon Jun 11, 2007 11:04 pm
by Arawn
Check the log for whatever MTA your using (likely Postfix) and see what the error is occurring. Probably in /var/log/mail but I am guessing as I don't use Fedora.

Most ISP's will bounce any mail from a domain they can't verify (which means lookup using a DNS).

Posted: Tue Jun 12, 2007 9:24 am
by TreyAU21
Arawn wrote:Check the log for whatever MTA your using (likely Postfix) and see what the error is occurring. Probably in /var/log/mail but I am guessing as I don't use Fedora.

Most ISP's will bounce any mail from a domain they can't verify (which means lookup using a DNS).
I didn't find anything in the maillog, but I discovered something in the messages log file. After running my script twice in a row, I noticed these messages being appended to the messages log file. See below:

Code: Select all

Jun 12 10:19:58 moonbase kernel: audit(1181657998.780:12): avc:  denied  { execute } for  pid=7245 comm="httpd" name="bash" dev=dm-0 ino=6094878 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file

Jun 12 10:20:45 moonbase kernel: audit(1181658045.539:13): avc:  denied  { execute } for  pid=7252 comm="httpd" name="bash" dev=dm-0 ino=6094878 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
Any idea what this could lead to? It seems to be pointing towards Apache. I'll look through the httpd.conf file and see if I come up with anything. Any suggestions would be greatly appreciated though.

Posted: Tue Jun 12, 2007 10:22 am
by RobertGonzalez
Isn't there an apache config line that points to the mail program (usually sendmail)? Maybe that is the issue?

Posted: Tue Jun 12, 2007 1:30 pm
by TreyAU21
I resolved this issue and as we expected it was a server configuration problem. Well, let me clarify... I didn't really 'fix' anything, I simply disabled the selinux service (which as it was explained to me monitors intercommunications between services on the box). It must have been blocking the communication between Apache and Sendmail. I talked with another fella who said he ran into this issue on RedHat Enterprise 4. Something new must have been changed to the default installation in a way that it blocks the aforementioned communication. So, later I'll try to configure SELinux to work with what I'm trying to do... but for now, I just disabled it.

Thanks for all the help and suggestions,
Trey