0

I'm working on a php script which has to send emails. But my mail() function doesn't work. I know that I have to configure somehow php.ini and may be something else but I don't know what exactly and how. I installed sendmail, by the way. Any ideas? Thanks a lot. this is my code.

error_reporting(E_ALL); 

$to  = 'name@gmail.com';

$subject = 'subject';

$message = 'text';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=windows-1251' . "\r\n";
$headers .= 'To: user <user@example.com>' . "\r\n";
$headers .= 'From: server <server@example.com>' . "\r\n";

mail($to, $subject, $message, $headers);

in php.ini i put sendmail_path ="/usr/sbin/sendmail"

ps. i Use Ubuntu

guys, in the mail.log file i got

Apr 29 16:12:05 IT02 sendmail[7660]: My unqualified host name (IT02) unknown; sleeping    for retry 
Apr 29 16:13:05 IT02 sendmail[7660]: unable to qualify my own domain name (IT02) -- using short name 
Apr 29 16:13:05 IT02 sendmail[7660]: p3TED551007660: from=www-data, size=210, class=0, nrcpts=0, msgid=<201104291413.p3TED551007660@IT02>, bodytype=8BITMIME, relay=www-data@localhost 

Does anybody know what it means?

Brad
  • 159,648
  • 54
  • 349
  • 530
Kuen
  • 163
  • 2
  • 4
  • 13

1 Answers1

6

The first step would be to figure out where sendmail is installed. Once you know that path, go into your php.ini. You are looking for the sendmail_path setting. Set it appropriately.

If the path is set correctly, the result from a proper call to mail() should return true. (Note that the return value only lets you know if the message was passed on to sendmail [or SMTP in the case of Windows]. It does not guarantee that the e-mail went out, or that sendmail is configured correctly.) If it is returning true and you still aren't getting e-mail, then check your sendmail configuration.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • sendmail is installed. in the mail.log i got: Apr 29 16:12:05 IT02 sendmail[7660]: My unqualified host name (IT02) unknown; sleeping for retry Apr 29 16:13:05 IT02 sendmail[7660]: unable to qualify my own domain name (IT02) -- using short name Apr 29 16:13:05 IT02 sendmail[7660]: p3TED551007660: from=www-data, size=210, class=0, nrcpts=0, msgid=<201104291413.p3TED551007660@IT02>, bodytype=8BITMIME, relay=www-data@localhost – Kuen Apr 29 '11 at 14:14
  • So, your problem has nothing to do with PHP at all. Not to mention, this is an extremely common issue. http://www.fedoraforum.org/forum/archive/index.php/t-85365.html – Brad Apr 29 '11 at 14:58