gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 00:02:58 24 4
gpt4 key购买 nike

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

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

我该如何解决这个问题?

这是我目前的代码:

<?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 服务器:

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

当然你必须知道一个事件的 smtp 服务器。

祝你好运!

关于php - 警告 : mail() [function. 邮件]:无法连接到 "localhost"端口 25 的邮件服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2334250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com