php Mail()函数不起作用

时间:2011-04-29 13:10:26

标签: php email sendmail

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

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"

PS。我使用Ubuntu

伙计们,在mail.log文件中我得到了

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 

有人知道这意味着什么吗?

1 个答案:

答案 0 :(得分:6)

第一步是弄清楚sendmail的安装位置。一旦你知道了这条路径,就进入你的php.ini。您正在寻找sendmail_path设置。适当地设置它。

如果路径设置正确,则正确调用mail()的结果应返回true。 (请注意,返回值只会让您知道邮件是否已传递给sendmail [或Windows中的SMTP]。它不保证电子邮件已用完,或者sendmail配置正确。)如果是正在返回true但您仍然没有收到电子邮件,请检查您的sendmail配置。