hMailServer在线注册用户php教程
发表于 : 2016年3月18日, 17:40
此代码是一个PHP网页,用户自己注册账号,已经做过部分提示汉化。
来源于hms官网
测试后发现用注册的账户登录会提示错误
解决方法是在roundcubemail\config\config.inc.php 加入
代码: 全选
<?php
error_reporting(E_ALL & ~E_NOTICE);
//MySQL database connection information
//MySQL connection information:
$mysql_host = "localhost"; //Host Name
$mysql_user = "root"; //数据库用户名
$mysql_pass = "数据库密码"; //填写数据库密码
$mysql_db = "数据库名"; //填写数据库名
//General Configuration:
$form_title = "电子邮件注册"; //Name for this form
$account_max = "1"; //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!)
$admin_notify = "1"; //1 = yes & 0 = no 是否需要通知
$admin_email = "service@hmailserver.net"; //Administrators email to send notifications)
$admin_default_activate = "0"; //1 = yes & 0 = no -> If no, the administrator has to authorise the account
$accountisad = 0; // account is AD-account? 0 = no (default), 1 = yws;
$encryption = 2; //Password encryption level - 2 means md5;
$domain = 'hmailserver.net'; // 这里填写自己的域名。
$serv_webmail_url = 'http://mail.hmailserver.org/webadmin/'; // WEBMAIL的路径。
$url = $_SERVER["HTTP_HOST"];
$domain = (empty($domain))? $_SERVER["HTTP_HOST"] : $domain;
$domain = (substr($domain,0,4) == "www.")? strstr($domain, ".") : $domain;
// Protect database entries and use MD5 encryption
$strName = (isset($_POST['name']))? addslashes( $_POST['name'] ) : '';
$strUser = (isset($_POST['user']))? addslashes( $_POST['user'] ) : '';
$strDomain = addslashes( "$domain" );
$strPass1 = (isset($_POST['pass1']))? addslashes( $_POST['pass1'] ) : '';
//Connect to database using information from above
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
$select = mysql_select_db($mysql_db);
if (!$open || !$select)
{
echo "Unable to open database, contact your administrator!";
} else {
echo "<font size=\"+1\">$form_title</font><br><br>";
if ( isset($_POST['submit']) && $_POST['submit'] == 'create account' )
{
$domain_res = mysql_query("SELECT * FROM `hm_domains` WHERE `domainname` = '{$strDomain}' LIMIT 1");
if (!$domain_res)
{
die('Error while selecting data: ' . mysql_error());
}
$domain_info = mysql_fetch_array($domain_res, MYSQL_ASSOC);
//Check to see if email account exists, if not process signup
$account_res = mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$strDomain' LIMIT 1");
$v1 = mysql_num_rows($account_res);
If ($v1 >= 1)
{
echo "这封电子邮件的用户已经存在!!<br><br>请点击 <a href=\"javascript:history.go(-1)\">这里</a> 返回。";
return false;
} else {
if ( !$_POST['pass1'] || !$_POST['pass2'] )
{
echo "你没有输入密码!<br><br>请点击 <a href=\"javascript:history.go(-1)\">这里</a> 返回.";
}
elseif ( $_POST['pass1'] != $_POST['pass2'] )
{
echo "输入的密码不匹配!<br><br>请点击 <a href=\"javascript:history.go(-1)\">这里</a> 返回.";
} else {
$domain_id = $domain_info['domainid'];
$account_pass = ($encryption == 2)? md5( $strPass1 ) : $strPass1;
$account_add = mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$domain_id','$strUser@$strDomain','$account_pass','$admin_Default_activate','$accountisad','$account_max','$encryption')");
}
}
if (!$account_add)
{
die('<br><br>数据库错误,无法添加帐户。请与您的管理员联系!<br> ' . mysql_error());
}
If ($admin_Default_activate == 0)
{
echo "您的帐户已创建,但 <b>需要管理员激活.</b>";
echo "一旦你的申请被批准,你将收到一个确认信息。<br><br>";
} else {
echo "您的帐户已创建,并已准备好使用!<br><br>";
echo "Username: $strUser@$strDomain<br><br>";
if ( !empty($serv_webmail_url) ) echo "Webmail: <a href=\"$serv_webmail_url\">www.$strDomain/webmail</a><br>";
echo "POP3: mail.$strDomain<br>";
echo "IMAP: mail.$strDomain<br><br>";
echo "SMTP: mail.$strDomain";
$subject = "Welcome To $strDomain Email!";
$message = "这是确认您的帐户已创建。您可以登录到您的帐户,并开始使用它.";
mail("{$_POST['user']}@$strDomain", $subject, $message); //Send welcome message
}
if ($admin_Default_activate == 0 && $admin_notIfy == 1)
{
$admin_mail_subject = "Account Requires Activation!";
$admin_mail_message = "The email account {$_POST['user']}@$strDomain has been created by {$_POST['name']} and requires administration activation!\r\n\r\nPlease login to the admin control panel to verIfy and activate user account.\r\n\r\n";
mail($admin_email, $admin_mail_subject, $admin_mail_message);
}
elseif ($admin_Default_activate == 1 && $admin_notIfy == 1)
{
$admin_mail_subject = "New Account Created!";
$admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
mail($admin_email, $admin_mail_subject, $admin_mail_message);
}
}
}
//Email account signup page
echo "
<table width=\"350\" border=\"0\" cellpadding=\"0\" cellspacing=\"2\">
<form action=\"\" method=\"POST\">
<tr><td>姓名:</td><td><input type=\"text\" name=\"name\" size=\"21\"></td></tr>
<tr><td>E-Mail:</td><td><input type=\"text\" name=\"user\" size=\"21\"> @ ".$domain."</td></tr>
<tr><td>密码:</td><td><input type=\"password\" name=\"pass1\" size=\"21\"></td></tr>
<tr><td>密码:</td><td><input type=\"password\" name=\"pass2\" size=\"21\"> (确认)</td></tr>
<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"create account\" style=\"width: 98%\"></td></tr>
</form>
</table>";
?>测试后发现用注册的账户登录会提示错误
解决方法是在roundcubemail\config\config.inc.php 加入
代码: 全选
$config['junk_mbox'] = 'INBOX.spam';
$config['create_default_folders'] = true;