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

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

<?php $to=“”; $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’; }


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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Or actually on centos yum install sendmail <br> <br>Try installing sendmail. If you are on Ubuntu ‘sudo apt-get install sendmail’ <br> <br>PHPMailer with a gmail account is more likely to work consistently though.

Have you set up postfix or some other MTA on the droplet?