-2

I have a problem sending mail with PHP on a LAMP (redhat 7 server). I have configured sendmail, with which I am able to send email using the following:

$ sendmail toemail@something.com <press enter>
message body <press enter>
ctrl+d (sends message)

and the message is received by any mentioned email address, successfully.

But when I use the PHP scripts (working fine on other servers), PHP scripts are unable to send any email.

No error is there in /etc/mail/maillog/ and I have tried with different paths in php.ini in sendmail_path e.g:

/usr/sbin/sendmail -t -i

/usr/sbin/sendmail -t

/usr/sbin/sendmail

None of the three does anything.

permission for /usr/sbin/sendmail is 666.

Any of the possible PHP scripts that works everywhere, does not work in this new environment. One of the scripts which I tried is as below:

<?php if(mail("receipient@domain.com","A Subject Here","Hi there,\nThis email was sent using PHP's mail function.")) print "Email successfully sent"; else print "An error occured"; ?>

Please suggest.

1 Answers1

2

First of all, the path you are using for sendmail_path in php.ini is wrong. There is a missing / in the line, a typing mistake or a copy/paste failure I guess:

It should be like:

/usr/sbin/sendmail -t -I

/usr/sbin/sendmail -t

/usr/sbin/sendmail

You can find out the correct path for yourself, if you have access to the shell, type the following:

whereis sendmail

And you should also set permission to sendmail's binary to 755 using chmod so that php script is able to execute it.

For further diagnostic you should also check your apache error log (/var/log/httpd/error_log or similar location). You can find out your exact error log location for your default/virtual host by looking at the value for the following parameter in apache.conf or virtual host's .conf file:

ErrorLog
Diamond
  • 8,791
  • 3
  • 22
  • 37