警告:mail()[function.mail]:无法连接到“localhost”端口25的邮件服务器

时间:2010-02-25 13:27:15

标签: php mysql

我一直在尝试在我正在构建的网站上设置忘记密码设施,但每次我尝试加载页面时都会遇到错误:

  

警告:mail()[function.mail]:无法连接到“localhost”端口25的邮件服务器,验证php.ini中的“SMTP”和“smtp_port”设置或使用ini_set()

我该如何解决这个问题?

这是我到目前为止的代码:

<?php

            if (array_key_exists('forgot',$_POST)) {

      $email = $_POST['email']; 

      mysql_select_db($database_speedycms, $speedycms);
      $query_email = "SELECT * FROM tbl_users WHERE email='$email'";
      $email = mysql_query($query_email, $speedycms) or die(mysql_error());
      $row_email = mysql_fetch_assoc($email);
      $totalRows_user = mysql_num_rows($email);

      mysql_query("SELECT * FROM users WHERE email='$email'");

      if($totalRows_user == 0)

      {
      echo "<span class='form2'>We're sorry, but we could not find a user with that email address.<p>Please try again.<p>
      <a href='forgotpassword.php' class='form'>Return</a></span>";
      }

      else

      {


        // create a random password 
      function createRandomPassword() { 
      $chars = "abcdefghijkmnopqrstuvwxyz023456789"; 
         srand((double)microtime()*1000000); 
         $i = 0; 
         $pass = '' ; 
      while ($i <= 7) { 
            $num = rand() % 33; 
            $tmp = substr($chars, $num, 1); 
            $pass = $pass . $tmp; 
            $i++; 
          } 
         return $pass; 
      }
      $password = createRandomPassword(); 


      // generate email

      $username = $row_email['username'];
      $msg  = "Your new login information is:\n\n";
      $msg .= "Username: $username\n";
      $msg .= "Password: $password\n";

      mail("$email", "Speedy CMS Login Information", "$msg", "From:noreply@domain.com");

      // display message  

      echo "<span class='form2'>Thanks. Your new password has been sent to <i>".$row_email['email']."</i>.<p>
      <a href='index.php' class='form'>Return</a></span>";

      }

      exit;

      }

    ?>

5 个答案:

答案 0 :(得分:7)

看起来您的服务器没有运行smtp邮件服务器。您可以使用这些函数来设置不同的smtp服务器:

ini_set('SMTP', "server.com");
ini_set('smtp_port', "25");
ini_set('sendmail_from', "email@domain.com");

当然你必须知道一个活跃的smtp服务器。

祝你好运!

答案 1 :(得分:2)

您必须在php.ini文件

上配置这些值
SMTP = smtp.yourdomain.com  
smtp_port = 25 
username = info@yourdomain.com
password = yourmailpassord
sendmail_from = info@yourdomain.com

您可以提供与outlook配置相同的详细信息。有些服务器也在检查“sendmail_from”地址。

答案 2 :(得分:0)

您的网站运行的系统上似乎没有运行SMTP服务器。它是什么类型的服务器?

答案 3 :(得分:0)

看起来您正在使用本地PHP安装(使用WAMPSERVER,EasyPHP或其他),因为“真正的”主机很少错误配置他们的服务器。如果是这种情况,请编辑php.ini并使用您的ISP设置示例:

[mail function]
SMTP = mail.yourdomain.com
smtp_port = 25

答案 4 :(得分:0)

Warning: mail(): SMTP server response: 550 Access denied - Invalid HELO name (See 
RFC2821 4.1.1.1) in C:\AppServ\www\VOGUE\email.php on line 38

after add following codes...............

ini_set('SMTP',“ server.com”);

ini_set('smtp_port',“ 25”);

ini_set('sendmail_from',“ email@domain.com”);

how to add password of "sendmail_from" account???????