LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-28-2006, 07:03 PM   #1
Madone_SL_5.5
Member
 
Registered: Oct 2006
Location: Ogden, Utah
Distribution: Fedora 10
Posts: 66

Rep: Reputation: 15
mail() not sending from PHP script (Linux and Exim)


I run a Fedora Core 6 server as a host for my website. I use Exim instead of the default Sendmail (because it is a thousand times easier to setup).

As of yet, I have not been able to get the PHP mail() function to work in my website.

The pertinent portion of my php.ini file reads:

Quote:
[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from = email@thebikeshoppe;.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail.exim -t
sendmail_from = email@thebikeshoppe.com
You can see that I have included the proper wrapper for the Exim mailer--the same that works from my Linux shell.

I use a php script such as this:

Code:
<?php

$to = "recipient@example.com";
$subject = "Test Email";
$body = "This is a test.";

if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
  } else {
  echo("<p>Message delivery failed...</p>");
  }

?>
Which returns, "Message delivery failed...," and does not send the e-mail.

All output from the server is accepted in Iptables.

What am I missing? I'd really appreciate any suggestions.

Last edited by Madone_SL_5.5; 12-01-2006 at 06:24 PM.
 
Old 11-30-2006, 10:00 AM   #2
revof11
Member
 
Registered: Nov 2003
Location: Macungie, PA
Distribution: Fedora Core 9, Gentoo 2008.0
Posts: 108

Rep: Reputation: 15
I'm not sure if this will help you...
But this is what I suggest to everyone using mail functionality within PHP:
http://www.linuxquestions.org/questi...97#post2524497
 
Old 11-30-2006, 11:41 AM   #3
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
I read on some forums that exim is not that easy to use with PHP. They suggested me not to use exim with -i option but as I can see you are not. That makes exim to sit and wait for more input. What you need it this:
Quote:
sendmail_path = /path/to/exim -t
I am not sure that the path that you gave to the sendmail option in the php.ini file is proper. You might want to double check it and try to send a message using CLI. If it works than the problem is with PHP.
I don't know how it should be with Exim as I am using the sendmail alternative: postfix. Is is reliable and works good for me. No problems at all.
I know 2 more alternatives how to use Exim.
You might want to use IMAP to log in and send messages. It is fairly easy and works for some people.
The last one is a bit more complicated. A lot more complicated. You can write your own script that will use exim to send the message.
PHP Code:
<?php
function bsmtp($recipients$subject,
$body$headers = array(),
$sender"<>",  $helo "")
{

       
$exim "/usr/local/sbin/exim -bS";

       if ( 
$helo == "" )
       {
               
$helo $_SERVER["HTTP_HOST"];
       }

       if ( ! 
$headers )
       {

               if (
is_array($recipients))
               {
                       
$c="To: ";
                       foreach (
$recipients as $r)
                       {
                               
$toheader .= $c $r;
                               
$c ", ";
                       }
               }
               else
               {
                       
$toheader "To: " $recipients;
               }

               if ( 
ereg("@"$sender))
               {
                       
$fromheader "From: " $sender;
               }
               else
               {
                       
$fromheader "From: <MAILER-DAEMON@" $_SERVER["HTTP_HOST"] . ">";
               }

               
$subj "Subject: " $subject;

               
$headers = array($toheader$fromheader$subj);

       }

       
$headers[] = "X-Mailer: Dave's better php mail function";

       print 
"<PRE>";

       
$fd popen($exim"w");

       
fputs($fd"HELO " $helo "\n");
       
fputs($fd"MAIL FROM: " $sender "\n");
       if (
is_array($recipients))
       {
               foreach (
$recipients as $r)
               {
                       
fputs($fd"RCPT TO: " $r "\n");
               }
       }
       else
       {
               
fputs($fd"RCPT TO: " $recipients "\n");
       }

       
fputs($fd"DATA\n");

       foreach ( 
$headers as $h )
       {
               
fputs($fd$h "\n");
       }

       
fputs($fd"\n");

       foreach ( 
$body as $b )
       {
               
fputs($fd$b "\n");
       }

       
fputs($fd"\n.\nQUIT\n");

       
sleep(1);

       
pclose($fd);
}

}
?>
And one more thing. I don't know why but I have a feeling that you did not install exim properly and you did not remove sendmail as MTA.

Last edited by vargadanis; 11-30-2006 at 11:43 AM.
 
Old 12-01-2006, 05:55 PM   #4
Madone_SL_5.5
Member
 
Registered: Oct 2006
Location: Ogden, Utah
Distribution: Fedora 10
Posts: 66

Original Poster
Rep: Reputation: 15
I think Exim is a fairly straightforward setup. It works from the shell without any configuration. I'll check into that all the same.

How do I remove sendmail as the MTA? Is that something I need to manually do?
 
Old 12-01-2006, 08:22 PM   #5
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
On Ubuntu it is automatic if you want to install another MTA but if it is not on Fedora try to use yum remove or something similar. To be honest I have never used Fedora so I am not sure.
 
Old 12-02-2006, 12:55 PM   #6
Madone_SL_5.5
Member
 
Registered: Oct 2006
Location: Ogden, Utah
Distribution: Fedora 10
Posts: 66

Original Poster
Rep: Reputation: 15
I'm almost sure that removeal of the MTA upon uninstall is automatic. I used yum remove to remove sendmail.

Could my problem have anything to do with apache not having permission to access the sendmail.exim command? I have heard that the latest version (which I am using) is set up differently for security purposes. Does that sound reasonable? How would I check such a thing?

Are there other things I should be checking?
 
Old 12-03-2006, 10:05 PM   #7
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
I am sorry but that's all I know about it. If you test the stuff on local computer I wouldn't be worried about the MTA because on the remote server it should work 100% perfect. Sendmail or postfix will solve you program instantly and you do not have to modify your script to use it with exim on the remote server. Or at least I hope it will solve it immediately.

Let us know if you can solve the problem pls.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mail-function php sharp81 Linux - Software 3 02-17-2006 10:45 AM
php mail() function not working as it should on my box juancha Linux - Newbie 14 02-16-2006 01:43 PM
HELP !!! php mail function akamaru607 Programming 22 08-26-2005 03:44 PM
PHP - mail function saravanan1979 Programming 2 08-06-2003 02:46 AM
Using the PHP mail() Function !?!? Hdata Programming 0 06-22-2003 07:02 AM


All times are GMT -5. The time now is 10:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration