LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP mail() function not working with Exim (https://www.linuxquestions.org/questions/programming-9/php-mail-function-not-working-with-exim-505701/)

Madone_SL_5.5 11-28-2006 06:03 PM

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.

revof11 11-30-2006 09:00 AM

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

vargadanis 11-30-2006 10:41 AM

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.

Madone_SL_5.5 12-01-2006 04:55 PM

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?

vargadanis 12-01-2006 07:22 PM

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.

Madone_SL_5.5 12-02-2006 11:55 AM

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?

vargadanis 12-03-2006 09:05 PM

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.


All times are GMT -5. The time now is 01:56 AM.