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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2334250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:04:59  来源:igfitidea点击:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25

phpmysql

提问by methuselah

I've been trying to set up a forgot password facility on a website which I am building but each time I try to load the page I am greeted by the error:

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

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

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

How do I go about resolving this?

我该如何解决这个问题?

here is the code I have so far:

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

<?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:[email protected]");

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

      }

    ?>

回答by Bas

Looks like your server doesn't have a smtp mailserver running. You could use these functions to set a different smtp server:

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

ini_set('SMTP', "server.com");
ini_set('smtp_port', "25");
ini_set('sendmail_from', "[email protected]");

Of course you must know an active smtp server.

当然,您必须知道一个活动的 smtp 服务器。

Good luck!

祝你好运!

回答by sugunan

You have to configure these values on php.inifile

您必须在php.ini文件中配置这些值

SMTP = smtp.yourdomain.com  
smtp_port = 25 
username = [email protected]
password = yourmailpassord
sendmail_from = [email protected]

You can provide same details as in outlook config. Some servers are checking "sendmail_from" adress also.

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

回答by Gayan Chaturanga

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', "server.com");

ini_set('smtp_port', "25");

ini_set('smtp_port', "25");

ini_set('sendmail_from', "[email protected]");

ini_set('sendmail_from', "[email protected]");

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

回答by Rene Terstegen

It looks like you do not have a SMTP server running on the system your website is running. What kind a server is it?

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

回答by AlexV

Looks like you are using a local PHP installation (using WAMPSERVER, EasyPHP or else) because "real" hosts rarely misconfig their server. If it's the case, edit the php.ini and use your ISP settings example:

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

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