medium_grade
asked on
PHP mail() function not working...
I am running PHP 5.3.10
My PHP mail() function no longer works. Not sure why. Here is what my php.ini parameters are for sendmail (domain names have been changed),
I can run sendmail -vt from the command line and it works fine. I have verified that the sendmail path is correct. However, I simply can't get the mail() function to send any email. I tried running the following
And I get no errors. I am not sure where to go from here.
My PHP mail() function no longer works. Not sure why. Here is what my php.ini parameters are for sendmail (domain names have been changed),
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = info@MYDOMAIN
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = info@MYDOMAIN
I can run sendmail -vt from the command line and it works fine. I have verified that the sendmail path is correct. However, I simply can't get the mail() function to send any email. I tried running the following
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "info@MYDOMAIN";
$to = "NAME@TODOMAIN";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
And I get no errors. I am not sure where to go from here.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dave Baldwin,
I believe it is. The command I am using is this:
Where mail.txt contains the following:
This goes through just fine.
My OS environment is Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-24-virtual i686). It may also be worth mentioning that I recently updated PHP/Apache to the latest available to my distribution and it also updated sendmail/Postfix, I believe. Not sure why that would have broken anything seeing as how the sendmail path still works, but it's a consideration.
On a hunch that the issues might be permissions related, I checked the sendmail executable that lies at the path PHP should be trying and I found that it was an alias to "/etc/alternatives/sendmai l." I checked that path and found that it too was an alias to "/usr/lib/sm.bin/sendmail. " I checked THAT path and found that the executable there was set with the following permissions:
It looks to me like any should be able to execute the program, right? I don't see the execute bit set for the group, but that would only apply if the user that the Apache process runs under is a member of that group, right?
Let me know what you guys think. Thanks.
I believe it is. The command I am using is this:
sendmail -t < ~/mail.txt
Where mail.txt contains the following:
To: MYNAME@SOMEDOMAIN
Subject: sendmail test two
From: info@MYDOMAIN
And here goes the e-mail body, test test test..
This goes through just fine.
My OS environment is Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-24-virtual i686). It may also be worth mentioning that I recently updated PHP/Apache to the latest available to my distribution and it also updated sendmail/Postfix, I believe. Not sure why that would have broken anything seeing as how the sendmail path still works, but it's a consideration.
On a hunch that the issues might be permissions related, I checked the sendmail executable that lies at the path PHP should be trying and I found that it was an alias to "/etc/alternatives/sendmai
-rwxr-sr-x 1 root smmsp 861420 Sep 19 2013 sendmail
It looks to me like any should be able to execute the program, right? I don't see the execute bit set for the group, but that would only apply if the user that the Apache process runs under is a member of that group, right?
Let me know what you guys think. Thanks.
Hey, if you aren't willing to try my test, that's fine.
ASKER
Ray Paseur,
Nothing personal, sir. I am running a heavily customized older Drupal install on a custom VM. Even if upgrading to the latest and greatest PHP doesn't break the app, I am trying to see if I can get this to work first before resorting to moving the app to a whole new environment. After all, it worked fine for over 3 years.
Drupal has it's own built-in mail function which relies on the PHP one. I can't simply switch to another email mechanism as countless Drupal functions rely on it.
Nothing personal, sir. I am running a heavily customized older Drupal install on a custom VM. Even if upgrading to the latest and greatest PHP doesn't break the app, I am trying to see if I can get this to work first before resorting to moving the app to a whole new environment. After all, it worked fine for over 3 years.
Drupal has it's own built-in mail function which relies on the PHP one. I can't simply switch to another email mechanism as countless Drupal functions rely on it.
ASKER
Ended up setting up the site on a new Ubuntu instance. That probably should have been done at some point anyway. Thanks for the troubleshooting help.
http://php.net/archive/2017.php#id2017-03-16-2
After you've done the upgrade, come back and we'll go on with the mail() issues. There are so many things that can go wrong, and many of these things are outside of your control. Years ago, I gave up on sending automated mail and went with ConstantContact (Google 'em). If you decide you want to wade into the email swamp, read on.
PHP has important online documentation that you want to read.
http://php.net/manual/en/mail.requirements.php
http://php.net/manual/en/mail.configuration.php
http://php.net/manual/en/function.mail.php <<<--- Read the User-Contributed Notes
Mail has very stringent requirements for terminating lines in the headers. Before you try anything else, try sending mail to yourself at a Gmail account or similar. Use only the first three arguments: to, subject, body. Check the headers with "show original" and then try your mail() function again, adding your own headers in one at a time. You may want to terminate your headers with \r\n.