I tried searching a lot but unable to find how to actually setup a ubuntu server, so that I can send mails through php using mail() function in php.
I have apache2, mysql and php5 installed on my server.
I also agree there is a lack of tutorials for people who just need a script to send, e.g. error emails, and don't need a full-blown mail server.
First, if postfix not already installed do:
It prompts with a couple of questions. For the first I chose "Internet site"; for a machine behind a firewall I might choose smarthost instead. For the second question it defaults to the machine name; I appended a domain name that I control (so I can set DNS for it later, should I need to).
At this point you should be able to use "mail" from the commandline to send a test.
Then under /etc/php5/conf.d create a file (e.g. mailconfig.ini) with these contents:
Change email@example.com to your email address. They mean all email will look like it is sent by you, which can help prevent it being rejected. This is sufficient for just sending error emails to a developer.
(The above instructions tested on Ubuntu 10.04, 11.04, 11.10, 12.04)
P.S. As pointed out by razzed in the comments,
|show 2 more comments|
You'll need to setup the ubuntu server to be able to send mail ... as an example, you could install and configure postfix.
The Ubuntu documentation has a nice page at https://help.ubuntu.com/community/MailServer
Either go through the painful process of setting up a mail server directly on your server (postfix, etc) or use a library that will allow you to connect directly to a smtp server.
You should first install xmail package, and if it still does not work, have a look over here.