所以我制作了一个小的SMTP php代码,在完成表单时将电子邮件发送到所需的帐户,现在的问题是,当表单将要发送时,需要花费大量的时间来发送。所以我超过了时间,在超过时间结束后我收到了这个错误。
警告:从空值中创建默认对象 第15行的C:\ xampp \ htdocs \ SMTPClass.php
注意:未定义的变量:C:\ xampp \ htdocs \ SMTPClass.php中的HTTP_HOST 第39行
表格代码:
<?php
include('SMTPconfig.php');
include('SMTPClass.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass,
$from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form</title>
</head>
<body>
<form method="post" action="">
<table width="500px">
<tr>
<td width="20%">To : </td>
<td ><input type="text" name="to" /></td>
</tr>
<tr>
<td>From :</td>
<td><input type='text' name="from" /></td>
</tr>
<tr>
<td>Subject :</td>
<td><input type='text' name="sub" /></td>
</tr>
<tr>
<td>Message :</td>
<td><textarea name="message"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" Send " /></td>
</tr>
</table>
</form>
</body>
</html>
SMTP CLASSES:
<?php
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from,
$to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 25;
} else {
$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>
SMTP服务器:
<?php
$SmtpServer="smtp.mail.yahoo.com";
$SmtpPort="465";
$SmtpUser="username@yahoo.com";
$SmtpPass="yahoopassword";
?>