There are a lot of packages out there that will help you get going with PHP mail on Ubuntu. I´m going to tell you about one of the easiest ways to do it, with the minimal amount of lines.
Send emails from PHP with ssmtp
The installation process:
sudo apt-get install ssmtp
Then edit the /etc/ssmtp/ssmtp.conf file with this information:
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=<YOUR-EMAIL>@gmail.com
AuthPass=<YOUR-PASSWORD>
(or any other SMTP-server that you might want to use)
Final steps:
Find your php.ini file (usually in /etc/php5/cli/php.ini) and make sure the sendmail_path is:
sendmail_path = /usr/sbin/sendmail -t
Then restart your apache2-server with
service apache2 restart
Now you can send outgoing emails with PHP!