0
我想发送电子邮件从表格使用smtp没有身份验证...请帮助。 我打电话给托管公司,他们告诉我,我应该没有身份验证就这样做。我相信如果我通过认证它会更容易。以下是我在下面写的代码。发送smtp邮件没有身份验证使用php
function ProcessForm($values){
include('smtpConfig.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = 'mail';
$from = 'fromMail';
$subject = 'Website Contact';
$text = $values['text'];
$name = $values['name'];
$email = $values['email'];
$body = "
<style>
* {
font-family: verdana, helvetia, arial, sans-serif;
font-size: 14px;
}
table {
width: 600px;
background: #fff;
margin: auto;
border: #a9ee17 solid 4px;
}
table tr td {
font-family: verdana, helvetia, arial, sans-serif;
font-size: 14px;
}
</style>
A message has been sent from site. Its details are as follows:
<br/>
<br/>
<table cellpadding=10 cellspacing=0>
<tr>
<th><b>Field</b></th>
<th><b>Value</b></th>
</tr>
<tr class='row'>
<td><b>Name</b></td>
<td>$name</td>
</tr>
<tr class='row'>
<td><b>Email Address</b></td>
<td>$email</td>
</tr>
<tr class='row'>
<td><b>Message</b></td>
<td>$text</td>
</tr>
</table>
";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
echo '<h2 class="center success">Your message was sent. Thank you very much</h2>';
include_once 'static/contact-details.php';
}
}
下smtpConfig代码最初设置来接受STMP用户名和密码,但因为我试图使用SMTP没有任何身份验证,我删除了有关用户名和密码位,只留下SMTPSERVER和端口...默认的端口号通常是25,所以我想假设这不是问题。
<?php
//Server Address
$SmtpServer="smtp.host.co.za";
$SmtpPort="25"; //default
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$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, "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;
}
}
?>
代码进程没有错误但仍不发送邮件。