cannot receive email using mail() function in PHP. tried many things but nothing working

April 25, 2014 4.4k views
I am just making a very simple use of mail () function but it is also not working. the value of function is returning true. I can receive mail on my email if i upload this file to another server but when I use it on my droplet it don't works. my code is it is working on other website as I had tried it. but not working on digital ocean droplet so someone please help me our sorting this problem.
4 Answers

$to="contact@xyz.com";
$subject="subject";
$mail_body="Dear sir,
message";
$from="myemail@mydomain.x";

if (mail ($to,$subject,$mail_body,$from))
{
echo 'mail delivered successfully';
}
else
{
echo 'problem delivering mail';
}
Have you set up postfix or some other MTA on the droplet?
http://stackoverflow.com/questions/8803994/php-mail-not-working-for-some-reason

Try installing sendmail. If you are on Ubuntu 'sudo apt-get install sendmail'

PHPMailer with a gmail account is more likely to work consistently though. http://phpmailer.worxware.com/?pg=examplebgmail
Or actually on centos yum install sendmail
Have another answer? Share your knowledge.