PHP mail() function not sending email and no error was reported

The problem was that mail() method worked when invoked with php -r "mail('address@domain.tld', 'Subject', 'Message'); but when I tried it via the web server (apache in my case), in a php script, no email was sent and the mail method returned false. On top of this no error was displayed or logged anywhere not even error_get_last function did not return anything and I had display_errors and error_reporting activated and full E_ALL.

After trying all┬áthe possible tests that I could imagine I tried to send an email by executing the sendmail command form a php script. When I tried php’s shell_exec with sendmail:

shell_exec('/usr/sbin/sendmail');

and checked apache’s error logs got the error sh: /usr/sbin/sendmail: Permission denied. After I got this error it was obvious that the fix was to change the permissions for /var/qmail/bin/qmail-inject and /var/qmail/bin/sendmail so that apache can execute them.

Then said to myself: Happy developing! and that was it.

NOQUEUE: reject: RCPT from unknown[xxx.xxx.xxx.xxx]: 553 5.7.1 : Sender address rejected: not owned by user

This error was written in my maillog when I was trying to send an email with Thunderbird.

It seams that the reason for this error was the fact that I used on the outgoing server’s options a port number that was used for imap instead of the needed smtp server.

This error is really weird:

Mar 27 10:33:32 somehost postfix/smtpd[34322]: NOQUEUE: reject: RCPT from unknown[127.0.0.1]: 553 5.7.1 : Sender address rejected: not owned by user login_and_sender@example.com; from= to= proto=ESMTP helo=

To fix this check out the outgoing server settings to have set the correct smtp port number.