【问题标题】:How to fix Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\.. on line 22 ERROR如何解决警告:mail() [function.mail]:SMTP 服务器响应:需要 530 SMTP 身份验证。在 C:\xampp\htdocs\.. 第 22 行错误
【发布时间】:2012-07-08 19:05:13
【问题描述】:

我是 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 server response: 530 SMTP authentication is required。 有什么想法可能是错的吗? 谢谢

【问题讨论】:

    标签: php xampp mail-server


    【解决方案1】:

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

    Mail issues with PHP, Unable to send

    Error on sending mail with XAMPP

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

    【讨论】:

    • 感谢您的快速响应,我已将 hMailServer 用作邮件服务器,并尝试使用谷歌邮件和本地邮件但无济于事。关于我应该为谷歌邮件使用的设置有什么建议吗?
    • 尝试遵循本教程,设法修改了我之前所做的 php.ini。但是,将更改放在 sendmail 文件中的哪个位置并不完全清楚。你知道把它放在哪里吗?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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


        函数 authSendEmail($sendto, $replyto, $subject, $message, $namefrom=""){
        //SMTP + 服务器详情
        /* * * * 配置开始 * * * /
        $smtpServer = "mail.server.com";
        $port = "25";
        $timeout = "5";
        $username = "test@server.com";
        $password = "测试";
        $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;
        }
        
        ?>
        

        【讨论】:

          【解决方案5】:

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

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

          【讨论】:

            猜你喜欢
            • 2014-03-30
            • 2012-04-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-03-14
            • 2020-06-14
            • 2018-10-07
            • 2016-05-16
            相关资源
            最近更新 更多