I am working with a Redhat Linux server. A few months ago, I had written a simple user registration system in PHP5 using email as verification. I recall that it was working at that time. However, after recently testing the system, I find that the email is not actually being sent (I've tried a few email addresses from different domains, as well as checked spam folders).
As a test case, I tried the simple code below (using my actual email address as $to):
<html>
<head>
<title>Sending email using PHP</title>
</head>
<body>
<?php
$to = "myemail@gmail.com";
$subject = "Subject";
$message = "Message";
$header = "From:webmaster@mydomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$ret = mail ($to,$subject,$message,$header);
if( $ret == true )
{
echo "Message sent successfully.";
}
else
{
echo "Message could not be sent.";
}
?>
</body>
</html>
It echoes "Message sent successfully". I also tried using PHPMailer, which gives a successful message (I believe their implementation uses the mail() function as well).
Looking at php.ini, there is the following:
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
I am not that familiar with how SMTP servers work. What are some steps that I can take to troubleshoot this issue? Is this simply a matter of contacting the server admin or is there something I can change myself (I have root access)?
Edit:
From Andrzej's suggestion, I checked the maillog file and found these two lines from a recent attempt (I replaced my servername and email):
Mar 11 17:11:30 myservername sendmail[23240]: s2BLBU2x023240:
from=apache, size=149, class=0, nrcpts=1,
msgid=<201403112111.s2BLBU2x023240@myservername.com>,
relay=apache@localhost
Mar 11 17:11:30 myservername sendmail[23240]: s2BLBU2x023240:
to=myemail, ctladdr=apache (48/48), delay=00:00:00, xdelay=00:00:00,
mailer=relay, pri=30149, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0,
stat=Deferred: Connection refused by [127.0.0.1]