lior r
lior r

Reputation: 2290

sendmail and php mail() - "no recipients found"

I have installed sendmail on my Apache server (Ubuntu)

Everything seems to work find except an email is not beeing sent while using php mail();

I get an error on the Apache errorlog saying:

/usr/sbin/sendmail: no recipients found

This is the way I'm using the function:

$user_email = "[email protected]";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $user_email . "\r\n";
$headers .= 'From: Mydomain <[email protected]>' . "\r\n";

  mail($user_email,"subject","message",$headers);

Upvotes: 0

Views: 3947

Answers (3)

kevstev01
kevstev01

Reputation: 340

I installed ssmtp on my ubuntu/apache2/php set up, and I found I had to set the sendmail parameters in php.ini

mail.force_extra_parameters = -t

As I understand it, ssmtp emulates a sendmail set up, and the -t parameter forces the mta to scan the incoming mail (from PHP) for a 'To:' header.

As a point of note, I also had to change the symbolic link that the ssmtp install created to include the full path of the bin (ln -s /usr/sbin/ssmtp sendmail), so that the file could be found by apache

Upvotes: 2

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

What caused the error is that you had (in your original posted code):

$user_email = [email protected]

Both encompassing quotation marks and ending semi-colon were not present.

Here is the correct and proper form:

$user_email = "[email protected]";

It can also be written like this, using single quotes:

$user_email = '[email protected]';

As taken from the mail() function on PHP.net

http://php.net/manual/en/function.mail.php

Upvotes: 2

Novocaine
Novocaine

Reputation: 4786

$user_email = [email protected]

should be

$user_email = "[email protected]";

Upvotes: 4

Related Questions