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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月26日
  • 已采纳回答 12月18日
  • 修改了问题 12月7日
  • 创建了问题 12月7日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效