php Mail()函数不起作用

问题描述:

我正在制作一个必须发送电子邮件的php脚本。但是我的mail()函数不起作用。我知道我必须配置某种方式php.ini,可能是其他的东西,但是我不知道究竟是甚么。我安装了sendmail,顺便说一句。
任何想法?非常感谢。
这是我的代码。

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);

在php.ini我把 sendmail_path =/ usr / sbin / sendmail

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

ps。我使用Ubuntu

ps. i Use Ubuntu

个人,在mail.log文件中我有

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?

第一步是找出安装sendmail的位置。一旦你知道这个路径,进入你的php.ini。您正在寻找 sendmail_path 设置。

如果路径设置正确,则正确调用 mail()的结果应该返回 true 。 (请注意,返回值仅允许您知道该消息是否传递给sendmail [或在Windows的情况下为SMTP],不能保证电子邮件已经出现,或者sendmail配置正确。)如果是正在返回 true ,而您仍然没有收到电子邮件,然后检查您的sendmail配置。

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.