Jump to content

PHP mail() not working


php_guy

Recommended Posts

Hello all,

 

I am trying to get PHP's mail() function to work, but it's not. I'm just using a basic mail() example that I've used on other servers -- it works fine.

 

I've tried...

 

1) Setting the SMTP to the correct SMTP server in PHP ini file and using ini_set()

2) The port is correctly set to 25

3) I've set the sendmail path in PHP.INI to


; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t

 

The mail() function returns true, however it's not working!

 

I know it's not something with my machine blocking ports because I can use Perl and it works fine

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/227992-php-mail-not-working/
Share on other sites

FYI I've tried changing the sendmail configuration the following as well, to no avail

sendmail_path = "/usr/sbin/sendmail -t"
sendmail_path = "/usr/sbin/sendmail -t -i"

Same result, the code returns true, but I don't receive any email. I've tried different email addresses to see if it's a problem with my particular one (which, like I said, it shouldn't, I've used Perl to send an email fine on the same machine)

 

 

Please post the PHP code you're using to test this between


tags.

 

Ken

Hi Ken

 

Here's my code

ini_set("SMTP", "mail.isp.com");
$to = "[email protected]";
$subject = "PHP Sendmail Example";
$headers = "From: The Root Monster <[email protected]>\r\n" .
    "Reply-To: [email protected]\r\n" .
    "Content-type: text/html; charset=iso-8859-1\r\n";
$body = "This is a sample message -- Why does it take so long";

if( mail($to,$subject,$body,$headers) )
    echo "success!";
else
    echo "nope! nope!";

 

I WAS able to get things working by doing

apt-get install sendmail-bin
apt-get install sendmail

... But the mail takes so LONG to send! Normally it takes a second tops, but this is taking close to a minute. When I say, "takes long to send" i mean the actual php page takes almost a minute to respond (the task bar says "Waiting for domain....") and the output ("success!") is not printed for about a minute.

 

Any idea what it could be that's taking so long?

 

I'm not sure if you're familiar with Perl... But this perl code -- on the same machine -- takes about a second to send.... compared to the PHP code and sendmail command line which take forever


#!/usr/bin/perl -T
#!/usr/bin/perl -Tw

use strict;
use CGI;
use Mail::Sendmail;

my %mail = (
    To      => "me\@domain.com",
    From    => "The Perl Agent <perl\@domain.com>",
    Subject => "Perl Mail",
    Message => "Just the message body",
    smtp    => 'mail.isp.com',
    'Content-Type' => 'text/html; charset=iso-8859-1'
);
sendmail(%mail); # or die $Mail::Sendmail::error;
print "Content-type: text/html\n\n";
print "<html><body>";
print "OK. Log says:\n", $Mail::Sendmail::log;
print "</body></html>";

 

Presumably they use the same method to send mail, no?

 

 

Well, I just read that Perl's Mail function (at least the one that I used) does not use sendmail

Does Mail::Sendmail need a command-line sendmail?

No. It communicates directly with any local or remote SMTP server using only Perl sockets. This was actually it's primary "raison d'être".

Source: http://alma.ch/perl/Mail-Sendmail-FAQ.html

 

That explains why it works on Perl. I mean, I could always use PHP's PEAR or another Mail api thta does not use sendmail, but I would rather try to get sendmail to work... At this point, it seems to be a problem with sendmail, since sendmail at the command line does not work.

 

Has anyone run into this before?

 

 

 

Hey guys,

 

I've been trying a lot of things, and finally got it to work.... I'll try and remember what I did in case anyone runs into this in the future:

 

First, I'm running debian so it was recommended to use exim instead of sendmail explicitly... So I did apt-get install exim4-base. I think this must have replaced the symbolic link for /usr/sbin/sendmail to exim after I did this.

 

Anyway, I tried to run my PHP page agian. No luck

 

Then I tried to run sendmail directly from the command line and I got the error: "Mailing to remote domains not supported "

 

So I googled that error and found someone else had a similar problem here: http://himerus.com/blog/himerus/mailing-remote-domains-not-supported-debian-lenny

 

I had to run: dpkg-reconfigure exim4-config and choose "internet site; mail is sent and received directly using SMTP". I took the defaults for the other settings. This is also explained here: http://www.electrictoolbox.com/changing-exim4-settings-debian-5-lenny/

 

Whew!

 

What an epic journey and I hope this is solved... I will continue to test

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.