PHP Sendmail not working on Ubuntu 16.04 / PHP 7.0 (with test script)

Ran into an issue recently, needed to install sendmail on a server and even with PHP configured correct, absolutely no emails were going through.

A quick tip, check /var/log/syslog, it usually contains information on the error.

The error in this case was that the hostname was not configured to a FQDN e.g. the contents of /etc/hostname was example not

Here is a script to test email is working:

ini_set( 'display_errors', 1 );  
error_reporting( E_ALL );  
$to = "";
mail($to, 'PHP Test E-mail', 'This is a test e-mail ' . date('r'), ['From: server@'.php_uname('n')]);  
echo "Test email sent";  

It can be run from the commandline using php test.php or in the browser by accessing the URL.