I have been trying to send email for registration, invitations and so on.
On local development, emails get sent. However once on the server no mails arrive.
I installed postfix. I was trying to setup a mail server but gave up. So currently, If I type in terminal
peter# mail example@example.com
the email arrives. However, this does not send email:
$res = mail('example@example.com', 'subj', 'bodddd');
not only that, but echoing $res
gives nothing. Neither true
nor false
.
What and how do i do to make it working?
thanx
According to your comment above, it looks like your sendmail path is either wrong or commented out in your php.ini. It should be something like this:
sendmail_path = /usr/sbin/sendmail -t -i
If you're unsure where your sendmail binary resides, you may find it by using:
whereis sendmail
The solution that worked for me on shared hosting was to use the -f
additional parameter in the mail
function. Instead of ...
mail($to, $subject, $body, $headers);
I had to use ...
mail($to, $subject, $body, $headers, " -fvaliduser@validdomain.com");
According to the php manual the additional parameters are provides as additional arguments to sendmail. Note that the lack of space between -f
and the email seems intentional.
In my case on one particular host I did not have access to the postfix/sendmail logs. The original command returned true and a cpanel log showed it was accepted for delivery, however the recipient never received it.