跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

关于PHP提交表单自动发送邮件有关问题

关于PHP提交表单自动发送邮件问题。

最近做的一个网站,要实现一个功能就是提交表单自动发送表单内容到指定邮箱。因为对PHP比较陌生,但网站后台的CMS是PHP,所以只好硬着头皮来了。在网上找了段比较流行的代码。然后我现在的问题就是这段PHP代码如何与表单连接。我现在把代码贴出来请大家帮帮我。

php
debug = FALSE;$this->smtp_port = $smtp_port;$this->relay_host = $relay_host;$this->time_out = 30; //is used in fsockopen()#$this->auth = $auth;//auth$this->user = $user;$this->pass = $pass;#$this->host_name = "localhost"; //is used in HELO command$this->log_file ="";$this->sock = FALSE;}/* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = ""){$header="";$mail_from = $this->get_address($this->strip_comment($from));$body = ereg_replace("(^|())(\.)", "\1.\3", $body);$header .= "MIME-Version:1.0";if($mailtype=="HTML"){$header .= "Content-Type:text/html";}$header .= "To: ".$to."";if ($cc != "") {$header .= "Cc: ".$cc."";}$header .= "from: $from";$header .= "Subject: ".$subject."";$header .= $additional_headers;$header .= "Date: ".date("r")."";$header .= "X-Mailer:By Redhat (PHP/".phpversion().")";list($msec, $sec) = explode(" ", microtime());$header .= "Message-ID:";$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."");$sent = FALSE;continue;}if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {$this->log_write("E-mail has been sent to");} else {$this->log_write("Error: Cannot send email to");$sent = FALSE;}fclose($this->sock);$this->log_write("Disconnected from remote host");}echo "";echo $header;return $sent;}/* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = ""){if (!$this->smtp_putcmd("HELO", $helo)) {return $this->smtp_error("sending HELO command");}#auth if($this->auth){if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {return $this->smtp_error("sending HELO command");}if (!$this->smtp_putcmd("", base64_encode($this->pass))) {return $this->smtp_error("sending HELO command");}}#if (!$this->smtp_putcmd("MAIL", "from:")) {return $this->smtp_error("sending MAIL from command");

相关文章