Gzc。。。
2021-12-07 22:00
采纳率: 93.8%
浏览 23
已结题

win2012+php5.3+iis8.5邮件SMTP 用的是126邮箱配置要怎么弄呢

win2012+php5.3+iis8.5邮件SMTP 用的是126邮箱配置要怎么弄呢
发送函数是下面代码,邮件发送一直不成功,提示是500错误我已经把php.ini所有错误显示都开了,是我需要配置什么还是别的什么错误呢?现在是不知道从哪里找问题,怎么才能让邮件发送成功,具体应该怎么配置呢,原网站源码在linux系统运行都正常的只要配置好126邮箱的smtp就行

function sendmail($to,$fromname="",$subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
    {
        $mail_from = $this->get_address($this->strip_comment($this->from));
        $body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
        $header = "MIME-Version:1.0\r\n";

        if($mailtype=="HTML"){
            $header .= "Content-Type:text/html\r\n";
        }

        $header .= "To: ".$to."\r\n";

        if ($cc != "") {
            $header .= "Cc: ".$cc."\r\n";
        }
        if ($fromname!="") $header .= "From: ".$fromname."<".$this->from.">\r\n";
        if ($fromname=="") $header .= "From:<".$this->from.">\r\n";
        $header .= "Subject: ".$subject."\r\n";
        $header .= $additional_headers;
        $header .= "Date: ".date("r")."\r\n";
        $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
        $utfheader=iconv("GBK","UTF-8//IGNORE",$header);
        list($msec, $sec) = explode(" ", microtime());

        $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

        $TO = explode(",", $this->strip_comment($to));

        if ($cc != "") {
            $TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
        }


        if ($bcc != "") {
            $TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
        }

        $sent = TRUE;

        foreach ($TO as $rcpt_to) {
            $rcpt_to = $this->get_address($rcpt_to);
            
            if (!$this->smtp_sockopen($rcpt_to)) {
                $this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
                $sent = FALSE;
                continue;
            }

            if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $utfheader, $body)) {
                $this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
            } else {
                $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
                $sent = FALSE;
            }

            fclose($this->sock);

            $this->log_write("Disconnected from remote host\n");
        }
        return $sent;
    }

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • li_zhicheng_126 2021-12-07 22:35
    最佳回答

    建议使用PHPMailer这个类库,功能强大,使用简单
    https://github.com/PHPMailer/PHPMailer

    评论
    解决 无用
    打赏 举报 编辑记录

相关推荐 更多相似问题