A very common post-install issue for simple websites is sending email with PHP. Fortunately it is usually quite easy to debug, I have documented the most likely here.
Having recently set up a webserver on a VPS using apache2/PHP, I quickly realised PHP''s mail() function wasn''t working. It doesn't give very much helpful information back either, just sent: true or false. I've helped people fix PHP problems quite a bit in the past, and by far the most common post-install issue for simple websites is email.
If the mail() function returns true, this means that the mailserver has accepted the email for delivery, or at least given the impression that it has been accepted. If this is the case, then not receiving emails probably has nothing to do with PHP, but with the mailserver. The issue is now an email problem, so the best way to start is by looking for hints in the mailserver error logs, usually located at /var/log/maillog or similar.
If the mail() function returns false, then PHP has been unable to pass the email to the mail server successfully. In this case, start by verifying where the mail server is installed (PHP requires a local mail server for Linux, usually sendmail although I prefer postfix), check this corresponds to the sendmail_path field in php.ini and is accessible. Next check the mail log for hints (/var/log/maillog)
Remember to try to send an email just before you check the mail logs so that the error can be found easily at the bottom. Also, after making changes to php.ini, you must remember to restart apache if PHP is installed as a module rather than cgi-bin.
My mail issue: the mail server installed is postfix, which names its self ''sendmail'' to make installation of programs requiring sendmail to be presentmuch easier. It is located at /usr/sbin/sendmail My mail() function returned false, so I looked at the emd of the mail log first; tail /var/log/mail where I saw no error messages at all. Going back to php.ini I noticed sendmail_path was blank. I entered /usr/sbin/sendmail restarted apache and tried again. No luck. Back to the mail log I now saw:
"postfix/sendmail[6114]: fatal: Recipient addresses must be specified on the command line or via the -t option"
Obviously postfix isn''t getting the recipient list in the format it is expecting. Luckily, it provided the answer for me; postfix should be called with the -t option. Back to edit php.ini; vim /usr/local/lib/php.ini where I found;
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = /usr/sbin/sendmail
It hinted in the file that I should have used -t to start with! I also added -i for good measure (this specifies whether or not a ''.'' on a new line is classed as the end of data, which is usually the case when sending email). Restarting apache once more and running the following simple line of PHP it worked a treat;
<?php
$b = mail("
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
", "Subject", "Email Content");
if($b == true)
{
echo "Sent";
}
else
{
echo "Error sending...";
}
?>




