警告:mail() [function.mail]:无法连接到位于“localhost"的邮件服务器;端口 25 [英] Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25

查看:40
本文介绍了警告:mail() [function.mail]:无法连接到位于“localhost"的邮件服务器;端口 25的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

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()

我该如何解决这个问题?

How do I go about resolving this?

这是我目前的代码:

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

      }

    ?>

推荐答案

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

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

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

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

Of course you must know an active smtp server.

祝你好运!

这篇关于警告:mail() [function.mail]:无法连接到位于“localhost"的邮件服务器;端口 25的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆