Linux – How to make Ubuntu Server 12.04 can send mail

apache-2.2linuxsendmailUbuntu

I have a Ubuntu Server 12.04 use to run my Webapp. I assume my Webapp wrote in PHP5, run-time enviroment is LAMP, domain is mywebapp.com. When visitor register account on mywebapp.com, website will send a confirm email automatically. But my system cannot send mail to user's inbox.

I don't think the code of mywebapp.com has error, because it uses the built-in function mail() and runs well on hostgator.com and Hostpapa.com. I have tried installing sendmail by using the command sudo apt-get install sendmail. But nothing changed.

Can you help me configure this system so that mywebapp.com can send mails to users automatically, without using a 3rd party email service like as Gmail or Hotmail, just using the mail() function; all aspects of the problem, about:

  • Config DNS records
  • What are app/packages need to install on Ubuntu Server 12.04
  • Config router: open port, NAT,…
  • Config Apache, PHP.ini or other

Best Answer

My suggestion would be to remove sendmail (it's not a good nor light MTA) and replace it with postfix, when you install postfix using ubuntu's normal software installation process (either apt cli or Ubuntu Software Center) it will ask what kind of mail server you want to install, the correct answer depends on whether the machine is a full server or just a development/staging environment.

If it's a normal server use "internet site" if it's a development environment use "Internet with Smart host" and specify ask your Internet provider or Network Administrator for your smtp server details.

If you need to change postfix's configuration most of it will be in /etc/postfix/main.cf, however because because you don't want your server becoming an open relay, after applying any configuration changes use http://www.checkor.com/ to test that it's not.

Given default php.ini settings you should then be able to send out emails via the mail() php function.

Related Topic