2012-07-09 27 views
2

我是PHP新手,並以腳本爲例在線。 我已經安裝了Xampp,並且php已安裝並正在運行。 我試圖用hMailServer設置本地郵件服務器,但是我不完全確定它是否設置正確。 總之,這裏的PHP代碼:如何解決警告:mail()[function.mail]:SMTP服務器響應:530 SMTP認證是必需的。在C: xampp htdocs ..在線22錯誤

<?php 

$subject=""; 
$detail=""; 
$customer_mail=""; 
$name=""; 

// Contact subject 
$subject ="$subject"; 

// Details 
$message="$detail"; 

// Mail of sender 
$mail_from="$customer_mail"; 

// From 
$header="from: $name <$mail_from>"; 

// Enter your email address 
$to ='[email protected]'; 
$send_contact=mail($to,$subject,$message,$header); 

// Check, if message sent to your email 
// display message "We've recived your information" 
if($send_contact){ 
echo "We've recived your contact information"; 
} 
else { 
echo "ERROR"; 
} 
?> 

以及相應的HTML代碼:

<table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> 
<tr> 
<td><strong>Contact Form </strong></td> 
</tr> 
</table> 
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> 
<tr> 
<td><form name="form1" method="post" action="test.php"> 
<table width="100%" border="0" cellspacing="1" cellpadding="3"> 
<tr> 
<td width="16%">Subject</td> 
<td width="2%">:</td> 
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td> 
</tr> 
<tr> 
<td>Detail</td> 
<td>:</td> 
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td> 
</tr> 
<tr> 
<td>Name</td> 
<td>:</td> 
<td><input name="name" type="text" id="name" size="50"></td> 
</tr> 
<tr> 
<td>Email</td> 
<td>:</td> 
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> 
</tr> 
</table> 
</form> 
</td> 
</tr> 
</table> 

當我提交表單我得到的錯誤警告:電子郵件()[function.mail]:SMTP服務器響應:530 SMTP認證是必需的。 任何想法可能是錯誤的? 謝謝

回答

0

Xampp沒有內置郵件服務器。您需要設置一個。

Mail issues with PHP, Unable to send

Error on sending mail with XAMPP

替代使用的另一STMP服務器(即Googlemail電子郵件)和郵件庫如PEAR:郵件或swiftmailer建立與登錄憑證

+0

感謝您的快速響應,我已經使用郵件服務器的hMailServer,並嘗試使用谷歌郵件和本地但無濟於事。有關我應該用於Google郵件的設置的任何建議? – 2012-07-09 11:34:54

+0

請參閱http://effectivewebdesigns.blogspot.de/2010/09/smtp-from-xampp-on-localhost-using-your.html – worenga 2012-07-09 11:54:12

+0

試圖按照本教程設法修改之前完成的php.ini 。但是,在sendmail文件中將更改放在哪裏並不是很明顯。你有什麼想法把它放在哪裏? – 2012-07-09 12:20:54

0

其PHP一個IMAP/SMTP連接這是沒有配置,你可以更新指向一個有效的SMTP服務器 在php.ini查找[mail function]這是僅適用於Windows 您可能希望設置本地郵件服務器,因爲不支持密碼或 使用的PHPMailer從 http://sourceforge.net/projects/phpmailer它不支持登錄

-2

/** * 返回錯誤字符串或null如果成功 */


功能 authSendEmail($ SENDTO,$的replyTo,$主題,$消息,$ namefrom = 「」){
// SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * /
$ smtpServer =「mail.server.com」;
$ port =「25」;
$ timeout =「5」;
$ username =「[email protected]」;
$ password =「test」;
$ newLine =「\ r \ n」;
/
* * *組態結束* * * * */

/* 
    2ХХ — команда успешно выполнена 
    3XX — ожидаются дополнительные данные от клиента 
    4ХХ — временная ошибка, клиент должен произвести следующую попытку через некоторое время 
    5ХХ — неустранимая ошибка 
    */ 


    //0 //Connect to the host on the specified port 
     $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if(empty($smtpConnect) || $smtpResponse{0} !='2') 
     { 
     return "Failed to connect: $smtpResponse"; 
     } 


    //1 //hello server 
     fputs($smtpConnect,"EHLO servername" . $newLine); 
     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 
     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 
     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 
     $smtpResponse = fgets ($smtpConnect); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

    //2 //Request Auth Login 
     fputs($smtpConnect,"AUTH LOGIN" . $newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='3') 
     return "Failed: $smtpResponse"; 

    //3 //Send username 
     fputs($smtpConnect, base64_encode($username).$newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='3') 
     return "Authentification failed: $smtpResponse"; 

    //4 //Send password 
     fputs($smtpConnect, base64_encode($password).$newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 


    //6 //Email From 
     fputs($smtpConnect, "MAIL FROM: ".$username . $newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

    //7 //Email To 
     fputs($smtpConnect, "RCPT TO: ".$sendto . $newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

    //8 //The Email 
     fputs($smtpConnect, "DATA" . $newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='3') 
     return "Failed: $smtpResponse"; 

    //9 //Construct Headers 
     $headers = "MIME-Version: 1.0" . $newLine; 
     $headers .= "Content-type: text/html; charset=windows-1251" . $newLine; 
     $headers .= "To: Администратор <$sendto>" . $newLine; 
     $headers .= "From: $namefrom <$username>" . $newLine; 
     $headers .= "Reply-To: $namefrom <$replyto>" . $newLine; 
     $headers .= "X-Mailer: ".phpversion(). $newLine; 

     fputs($smtpConnect, "Subject: $subject\n$headers\n\n$message\n.\n"); 
     $smtpResponse = fgets($smtpConnect, 515); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 


    //10 // Say Bye to SMTP 
     fputs($smtpConnect,"QUIT" . $newLine); 
     $smtpResponse = fgets($smtpConnect, 1024); 
     if($smtpResponse{0} !='2') 
     return "Failed: $smtpResponse"; 

     return false; 
} 

?> 
相關問題