I have the following code in sendmail.php:
#!/usr/bin/php
<?php
$to = "testmail@gmail.com";
$subject = "TestSubject";
$body = "TestBody";
if (mail($to, $subject, $body)){
echo "Mail Sent";
}else {
echo "Mail Failed";
}
?>
If I visit the web pathtothefile/sendmail.php it sends the mail OK. but if i make in a shell:
chmod 755 sendmail.php
./sendmail.php
It says "Mail Sent" but nothing is sent. Why is that happening? Thanks
As Tuong Le suggested I would look at your php.ini file. Also after reviewing
http://php.net/manual/en/function.mail.php
You may want to check your code once through to make sure you have all the necessary information.
If I was in your situation I would take out my own code and insert the sample code directly from the php manual to see where your issue might be occurring.
Try the following just to see if your mail gets sent out?
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "
" .
'Reply-To: webmaster@example.com' . "
" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>