我一直在尝试在我正在构建的网站上设置忘记密码功能,但每次尝试加载页面时都会遇到错误:
警告: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:[email protected] /cdn-cgi/l/email-protection");
// 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 protected] /cdn-cgi/l/email-protection");
当然,您必须知道一个活动的 smtp 服务器。
祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)