I am using centos Server and have to send the mail to the user so i copied running code of mine from one server and used it in here, but it is not sending mails.
Code is :
$to = $email; //writing mail to the user
$subject = "Hii";
$message = "<table>
<tr><td> Hello ".$email.",</td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
</table>" ;
$from = "example@domain.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Team <example@domain.com>' . "\r\n";
if(mail($to,$subject,$message,$headers))
{
echo "0";// mail sent Successfully.
}
else
{
echo "1";
}
It always print 1. Same code running fine on other project. Please guide me what i can do to enable it here too?
Any help will be highly appreciated!
After installing sendmail* and running the following commands:
I still had the same issue. I checked my
/var/log/maillogand saw an error:After more searching, I changed
/etc/hostsfrom:to:
and now the mail function is now working fine.