如何修复警告:mail()[function.mail]:SMTP服务器响应:530需要SMTP身份验证。在C:\ xampp \ htdocs \ ..第22行ERROR

时间:2012-07-09 11:24:42

标签: php xampp mail-server

我是PHP的新手,并在网上以脚本为例。 我已经设置了Xampp并安装了php并正常工作。 我试图用hMailServer设置本地邮件服务器,但是我不能完全确定它是否正确设置。 无论如何,这是PHP代码:

<?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 ='sean.myers92@gmail.com';
$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>

当我提交表单时,我收到错误警告:mail()[function.mail]:SMTP服务器响应:530需要SMTP身份验证。 什么想法可能是错的? 感谢

5 个答案:

答案 0 :(得分:4)

来自hMailServer的论坛:http://www.hmailserver.com/forum/viewtopic.php?f=6&t=22039

在IP范围内。转到我的计算机IP范围并取消本地外部和/或外部外部认证。

答案 1 :(得分:0)

Xampp没有内置邮件服务器。你需要设置一个。

Mail issues with PHP, Unable to send

Error on sending mail with XAMPP

替代使用另一个stmp服务器(即googlemail)和邮件库(如PEAR:Mail或swiftmailer)来建立与登录凭据的imap / smtp连接

答案 2 :(得分:0)

它没有配置的php你可以更新为指向有效的smtp服务器 在php.ini中查找[mail function]这仅适用于Windows 您可能希望在本地设置邮件服务器,因为不支持密码或 使用phpmailer提供 支持登录的http://sourceforge.net/projects/phpmailer

答案 3 :(得分:0)

从此链接http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list下载最新的phpmailer并阅读其gmail教程。对我来说它也适用于本地系统:) +它是非常简单的教程。

答案 4 :(得分:-2)

  

/ **        *返回错误字符串,如果成功则返回null        * /

     


功能 authSendEmail($ sendto,$ replyto,$ subject,$ message,$ namefrom =“”){       
// SMTP +服务器详细信息       
/ * * * * CONFIGURATION START * * * /       
$ smtpServer =“mail.server.com”;       
$ port =“25”;       
$ timeout =“5”;       
$ username =“test@server.com”;       
$ password =“test”;       
$ newLine =“\ r \ n”;   
      /
* * * CONFIGURATION END * * * * * /

  /*
  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;
}

?>