邮件发送不成功,提示:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\wwwroot\study_php\fun.php on line 110
failedphp发邮件类代码如下:class MailSend {
var $body;
var $to;
var $header;
var $object;
function MailSend($_to, $_object, $_body) {
$this->body = $_body;
$this->object = $_object;
$this->to = $_to;
}
function send() {
//$this->setheader();
if (mail ( $this->to, $this->object, $this->body )) {
echo "Succeed";
} else {
echo "failed";
}
}
}
调用代码:<?php
require_once("fun.php");
$mailSend=new MailSend("[email protected]","first","Just for try");
$mailSend->send();
?>php.ini配置如下:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25; For Win32 only.
sendmail_from = me@localhost高手快来看看是什么问题?

解决方案 »

  1.   

    class MailSend {
        var $body;
        var $to;
        var $header;
        var $object;
        function MailSend($_to, $_object, $_body) {
            $this->body = $_body;
            $this->object = $_object;
            $this->to = $_to;
        }
                function send() {
            $this->MailSend( xx, xx, xx );
            if ( mail ( $this->to, $this->object, $this->body ) ) {  // 感觉还是少了个参数
                echo "Succeed";
            } else {
                echo "failed";
            }
        }
    }
      

  2.   

    mail()函数还有个header的参数项,是可加可不加的。这样应该就可以吧,都被搞败了,这种warning,就像没有开smtp服务器似的,开IIS带的那个smtp服务器可以吧?又试了个mail direct pro的smtp服务器,一样的效果。不知道哪里出错了。
      

  3.   

    ini_set("SMTP","smtp.example.com" );
    ini_set('sendmail_from', '[email protected]'); 
      

  4.   

    试了一下phpmailer,同样发送成功,但是收件邮箱没有收到邮件,不解是什么原因?
      

  5.   

    有些服务器对自设的From有检查,如果有冒充的可能性就拒绝接收.
    比如mail函数的第五个参数要加 [email protected],
    SPF记录要在DNS上设好:
    my.domain.com.        IN      TXT "v=spf1 +ip4:xxx.xxx.xxx.xxx ~all"
      

  6.   

    ok!!为了看日志,没用IIS,换了个邮件服务器,ok!只不过被当成垃圾邮件处理了。