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

lsmepo6l  于 2023-01-16  发布在  PHP
关注(0)|答案(5)|浏览(208)

我一直试图在我正在建设的网站上设置一个忘记密码的设施,但每次我试图加载页面,我迎接的错误:
警告:mail()[函数. 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;

      }

    ?>
4sup72z8

4sup72z81#

您的服务器似乎没有运行smtp邮件服务器。您可以使用以下函数设置其他smtp服务器:

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

当然,您必须知道一个活动的smtp服务器。
祝你好运!

fnvucqvd

fnvucqvd2#

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

SMTP = smtp.yourdomain.com  
smtp_port = 25 
username = info@yourdomain.com
password = yourmailpassord
sendmail_from = info@yourdomain.com

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

nue99wik

nue99wik3#

您的网站运行的系统上似乎没有运行SMTP服务器。这是哪种服务器?

34gzjxbg

34gzjxbg4#

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

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

frebpwbc5#

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端口”,“25”);
ini_set('发送邮件来源',“email@domain.com“);

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

相关问题