2014-12-05 115 views
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; 
} 
} 
?> 

代碼進程沒有錯誤但仍不發送郵件。

回答

0

您的託管公司都在談論一個參數

$mail->SMTPAuth = MAIL_AUTENTIC;    // enable SMTP autenticacion 

MAIL_AUTENTIC應該是true或false來啓用或不。在你的情況虛假

一些變量已經previosly定義,如:

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('[email protected]', 'Envios');   // Reply address 

    $mail->AddAddress($TO); 
    $mail->SetFrom('[email protected]', 'Bla bla'); 
    $mail->AddReplyTo('[email protected]', '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; 

} 
相關問題