Enable PHP mail() function on Ubuntu
Introduction
This is a short guide covers how to enable the mail()
function in PHP on Ubuntu.
Here are the steps I took to get sendmail working on my Ubuntu server.
Step 1: Install sendmail
The first thing you need to do is install the sendmail package. Do this by running the following command in your terminal:
$ sudo apt-get install sendmail
Sendmail might already be installed, but just in case, enter above into your terminal:
Step 2: Configure sendmail
After the previous command finishes installing the sendmail package, you need to configure it. You can do that by running the following command, which will configure the mail server:
$ sudo sendmailconfig
You need to choose Yes to every question or otherwise configure it as you see fit.
Step 3 (Optional): Edit hosts file
To edit your server's hosts file, access it by entering the following command into the terminal:
$ sudo vim /etc/hosts
Step 4: Restart Web Server
At this point emails sent via PHP's mail()
function should be sending successfully without much delay. It is not necessary to restart server, but let's restart server just for good measure.
For Apache Server, you can enter the following command to restart the server.
$ sudo service apache2 restart
For Nginx Server, you can enter the following command to restart the server:
$ sudo service nginx restart
That's it! You can now use the mail()
function in your PHP app.. I hope this solved the problem for you.
References & Resources
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync