PHP发送不工作

问题描述:

$to = "[email protected]"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 
if (mail($to, $subject, $body)) { 
    echo("pMessage successfully sent!/p"); 
} else { 
    echo("pMessage delivery failed.../p"); 
} 

邮件代码写了基本的PHP sendmail的代码,但它给了我下面的错误:PHP发送不工作

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\mail.php on line 5 Message delivery failed...

我改变了``php.ini文件,并把[email protected]但仍是问题仍然存在。 第一次写邮件脚本。

我做错了什么?有一个更好的方法吗?

+2

我认为这是值得一提的是,把你的真实电子邮件在互联网上明文地址只是要求通过spambots收获。我希望你稍微混淆一下,因为我不知道你的真实电子邮件地址,所以我只是没有看到它。 :D – 2009-07-09 17:21:02

additional_headers (optional)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).

Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini. Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

我希望有帮助。

首先,请检查您编辑的正确php.ini - 将phpinfo();添加到您的脚本输出诊断信息中,包括php.ini的位置。您也应该能够在这里看到配置的“sendmail_from”值。

做不到这一点,提供了从头部,通过usoban

$hdrs="From: [email protected]"; 
mail($to, $subject, $body, $hdrs); 
+0

我编辑了正确的php.ini文件,但仍然有错误 – anand 2009-07-09 15:31:55

指示如果编辑了正确的php.ini,它并不能反映你的变化,你可能需要重新启动你的web服务,尽可能多环境只会在服务器启动时加载php.ini。

而不是在php.ini中设置表单地址,而是将其发送到像usoban这样的标题中。

当您在同一个设置中托管另一个站点时,这可以节省您的麻烦,并且下次忘记设置标题。

PHP mail()函数会产生很多问题。当您最终在服务器上运行它时,您会注意到您的电子邮件最终会出现在用户的垃圾邮件文件夹中。

我会建议使用的PHP SMTP库,而不是一个发送邮件:

我遇到了同样的问题,结果是因为我的服务器使用[email protected]作为发件人电子邮件地址,即使我在标题中指定了自己的邮件地址。

我发现其他地方的答案是一个第五个参数添加到邮件调用强制系统使用,从我指定的邮箱地址:

$from = '[email protected]' 
$xheaders = "From: " . $from . " <" . $from . ">\n"; 
$i = mail("$useremail","$subject","$content",$xheaders,'-f [email protected]');