• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

php mail() function not working

D

dave_s_wang

Guest
the php mail() function doesn't work in my installation of plesk. I've looked around on the forum and haven't found any solutions to this issue. What are the first steps to trouble shoot this?

this is the same php code that is not working:

<?php
mail('[email protected]', 'test', 'test');
?>

-d
 
Upload the following php script as "sendmail.php" to your server. This php script will test your mail() function:


<!--
This is a script, written and designed to test the functionality of the
PHP mail() function on a web hosting account. I offer no warrenty with
this script. Anyone can use and distribute the script freely.
-->

<html>
<head><title>PHP Mail() test</title></head>
<body>

This form will attempt to send a test email. Please enter where this test should be sent to<br><p>
<form action = "sendmail.php" method = "post" name="sendmail">
Enter an email address: <input type = "text" name = "to"><br>
<input type="submit" value="Send" name="submit"><input type="reset" value="Reset" name="reset"><br><p>



<?php

if(isset($_POST['to']))
{
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['SCRIPT_URI'];
$mail_to=$_POST['to'];
$mail_subject="Test email from $host";
$mail_body="This is a test email, sent from $uri";
$header = "Content-type: text/html\n";
$header .= "From: \"PHP mail() Test Script\"<noreply@$host>\n";


if(mail($mail_to, $mail_subject, $mail_body,$header))
{
print "Email sent successfully!<img src=\"http://dubovik.us/happygir.jpg\">";
}
else
{
print "Email did not send<img src=\"http://dubovik.us/madgir.jpg\">";
}
}
?>

</body>
</html>
 
i get a "Email did not send" using the script. for some reason, the mail() function is returning an error code even tho i am passing in the correct values.

in my /var/log/httpd/error_log i get :
sh: /usr/sbin/sendmail: Permission denied

ls -al on /usr/sbin/sendmail is :
lrwxrwxrwx 1 root root 23 Oct 11 19:21 /usr/sbin/sendmail -> /var/qmail/bin/sendmail

ls -al on /var/qmail/bin/sendmail is :
-r-xr-xr-x 1 root qmail 9756 Aug 24 02:21 /var/qmail/bin/sendmail

what should the correct permissions be?

-d
 
You have the same permissions set for qmail-inject that I do. But I don't use qmail to send mail in php. I use the sendmail program. In the php.ini file, my sendmail_path is /usr/bin/sendmail -t -i

Sorry I can't help with qmail
 
i changed it back to /usr/sbin/sendmail -t -i and i got the error i wrote above.

-d
 
You have the same permissions set as I do. Strange that it reports a permissions problem in the log file. I will continue to check my notes to see If I can come up with a suggestion for you.
 
In your php.ini file, try changing the path to sendmail from the symlink to accessing the sendmail program directly:



/var/qmail/bin/sendmail



There maybe a problem with your symlinks
If I come up with something else, I'll let you know.
 
I have a similar PHP mail issue. I just don't get any emails when php sends them. I used the sendmail.php test and it says, "Email sent successfully!", but, I never got the email in my inbox. I sent it to myself in the "Enter and email address:" but still nothing. Any help would be appreciated. It seems all mail works fine from the server but not on any of the PHP files I have installed.
 
After running the sendmail.php test, check your maillogs to see if the email actually comes into your server. There may be an indication in the maillogs as to what is happening.
 
There is nothing in the maillog at all. /var/log/maillog right?
 
/var/log/maillog

It should be /usr/local/psa//var/log/maillog

Also check your php.ini file in /etc/php.ini :

In the [Mail function] check sendmail_path Mine is sendmail_path = /usr/sbin/sendmail which is actually a symlink to /var/qmail/bin/sendmail
 
In that maillog I have this:

[root@host log]# tail maillog
Feb 2 13:18:30 host qmail: 1138904310.259883 triple bounce: discarding bounce/67873
Feb 2 13:18:30 host qmail: 1138904310.259915 end msg 67873
Feb 2 13:18:30 host qmail: 1138904310.396410 delivery 8: failure: Sorry,_I_couldn't_find_any_host_named_host.anodynetherapyllc.com._(#5.1.2)/
Feb 2 13:18:30 host qmail: 1138904310.396546 status: local 0/10 remote 1/20
Feb 2 13:18:30 host qmail: 1138904310.396582 triple bounce: discarding bounce/67877
Feb 2 13:18:30 host qmail: 1138904310.396614 end msg 67877
Feb 2 13:18:30 host qmail: 1138904310.447426 delivery 9: failure: Sorry,_I_couldn't_find_any_host_named_host.anodynetherapyllc.com._(#5.1.2)/
Feb 2 13:18:30 host qmail: 1138904310.447566 status: local 0/10 remote 0/20
Feb 2 13:18:30 host qmail: 1138904310.447599 triple bounce: discarding bounce/67881
Feb 2 13:18:30 host qmail: 1138904310.447632 end msg 67881
[root@host log]#
 
If that is all that is in your maillogs, then it appears that PHP's mail function does not know the correct path to sendmail or that the permissions for 'sendmail' are not correct.
 
sendmail has a sybolic link to qmail......

sendmail -> /var/qmail/bin/sendmail

permissions in /var/qmail/bin sendmail are r-xr-xr-x root qmail
 
Have you checked your local and remote queues to make sure the messages are locked in the queue awaiting processing?
 
I modified the me file in qmail and changed it from it's default of host.anodynetheropyllc.com to mail.anodynetherapyllc.com and the sendmail.php test just delivered me an email. Now to test the helpdesk...... Thanks SO much for your help, you got me on the right track. Hope that this solves it all.
 
Glad that I could help. I'm sorry that I never even thought about the me file. I'll file this away for next time.

Good Luck!
 
Originally posted by eric0524
I modified the me file in qmail and changed it from it's default of host.anodynetheropyllc.com to mail.anodynetherapyllc.com and the sendmail.php test just delivered me an email. Now to test the helpdesk...... Thanks SO much for your help, you got me on the right track. Hope that this solves it all.

what was it that you have done??
which file have you modified?
 
I modified /var/qmail/control/me file and changed the default host.yourdomainname.com to mail.yourdomainname.com then saved it. Restarted qmail via /etc/rc.d/init.d/qmail restart.
 
huh?

All that my me file contains is the name of my server... which is obviously not the mail URL

Shall I change the content to "mail.themaindomain.com" ?

What if I host various domain names? Use the main one?
 
Back
Top