24

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

mgPePe
  • 5,677
  • 12
  • 52
  • 85
  • 2
    Try looking in your maillog if anything is triggered at all. Usually located under /var/log/maillog. – Oldskool Oct 27 '11 at 07:47
  • 1
    `$res` should contain something, do you have `error_reporting = E_ALL` and `display_errors = On` ? also try to `var_dump($res);` –  Oct 27 '11 at 07:48
  • format should be mail(to,subject,message,headers,parameters) – devtut Oct 27 '11 at 07:50
  • @Oldskool: `Oct 27 07:53:12 mail postfix/sendmail[3127]: fatal: Recipient addresses must be specified on the command line or via the -t option`. @user973254: good one, var_dumps to `false`; Still not clear what to do – mgPePe Oct 27 '11 at 07:54
  • @Oldskool, it might be /var/log/mail.log or /var/log/mail.err – jlb Oct 27 '11 at 07:55
  • @madhudev: header and parameters are optional: http://php.net/manual/en/function.mail.php – mgPePe Oct 27 '11 at 07:55
  • _Oct 27 07:53:12 mail postfix/sendmail[3127]: fatal: Recipient addresses must be specified on the command line or via the -t option_ Seems to me as if you need to configure sendmail in your php.ini correctly – Hikaru-Shindo Oct 27 '11 at 08:01

2 Answers2

23

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
Oldskool
  • 34,211
  • 7
  • 53
  • 66
  • yes, I had to add the `-t` at the end. I don't know what it does or why it was missing, but it's working now. Graciaz – mgPePe Oct 27 '11 at 08:05
  • 2
    You could also use "which sendmail" instead of whereis this will only bring up the binary in the results. – Hikaru-Shindo Oct 27 '11 at 08:09
  • 2
    Nice, the "-t -i" flags indeed made the difference for me! :) What do they do? – Luis Miguel Serrano Aug 24 '13 at 15:08
  • 2
    @LuisMiguelSerrano from `## man sendmail` "-i Do not strip a leading dot from lines in incoming messages, and do not treat a dot on a line by itself as the end of an incoming message. This should be set if you are reading data from a file." ............ and "-t Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission." – Accountant م Jul 31 '18 at 14:17
8

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.

drgrog
  • 241
  • 2
  • 3