我正在尝试使用smtp从表单发送电子邮件而不进行身份验证...请帮助。 我打电话给托管公司,他们告诉我,我应该在没有认证的情况下这样做。我相信如果我对其进行身份验证会更容易。这是我在下面写的代码。
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;
}
}
?>
代码处理没有错误但仍然不发送邮件。
答案 0 :(得分:0)
您的托管公司正在讨论参数
$mail->SMTPAuth = MAIL_AUTENTIC; // enable SMTP autenticacion
MAIL_AUTENTIC应该是True还是False才能启用或不启用。在你的情况下是假的
一些变量已经被普遍定义,例如:
define('MAIL_AUTENTIC', true);
这是PHPMailer的一个例子
include('includes/class.phpmailer.php');
$mail = new PHPMailer(true); // true for exceptions in erors (try/catch)
$mail->IsSMTP();
try {
$mail->Host = MAIL_HOST; // SMTP server
$mail->SMTPDebug = 1; // SMTP debug 2 active 1 no active
$mail->SMTPAuth = MAIL_AUTENTIC; // enable SMTP autenticacion
$mail->Port = MAIL_PUERTO; // SMTP port
$mail->Username = MAIL_USUARIO; // SMTP user
$mail->Password = MAIL_PASSWORD; // SMTP password
$mail->AddReplyTo('ccccc@mydomain.net', 'Envios'); // Reply address
$mail->AddAddress($TO);
$mail->SetFrom('Myfrom@mydomain.net', 'Bla bla');
$mail->AddReplyTo('MyReply@mydomain.net', 'REsponse bla bla');
$mail->Subject = $SUBJ;
$mail->AltBody = 'Use HTML'; // optional
$mail->CharSet="utf-8";
$mail->IsHTML(true);
$mail->MsgHTML($MYTEXT);
$mail->Send();
}
catch (phpmailerException $e)
{
echo "Mailer Error: " . $mail->ErrorInfo;
}