我正在開發一個小型網站,該網站要求用戶註冊一個帳戶,然後向他們發送一封電子郵件,其中包含驗證該帳戶的詳細信息。點擊驗證電子郵件中的鏈接後,帳戶應該是積極的,用戶應該能夠登錄。 我已經從registration.php(註冊),login.php(登錄)和verify.php(驗證帳戶的激活)提供了3個PHP代碼段 !!我正在使用WAMP服務器創建數據庫,並按照表PHP註冊和登錄表單和電子郵件驗證/郵件服務器設置
注意:這是我在註冊頁面上收到的唯一錯誤。
警告:電子郵件():無法連接在本地主機"端口" 25至郵件服務器,驗證您的" SMTP "和" SMTP_PORT "設置在php.ini或C使用的ini_set():\ WAMP \ WWW \ ONLINE 1.我現在用的是hmailserver,但我不完全知道如何設置它 2.我需要給用戶時,監測:上線541
目前我有幾個問題銀行\和registration.php已被添加到數據庫中(我認爲這是電子郵件驗證鏈接被點擊後,才)
請告訴我什麼,我做錯了,這可怎麼固定
**REGISTRATION.PHP**
<div id="wrap">
<!-- start PHP code -->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with root .
mysql_select_db("registrations") or die(mysql_error()); // Select registration database.
$email="";
if(isset($_POST['fullname']) // Is the name field being posted; it does not matter whether it's empty or filled.
&& // This is the same as the AND in our statement; it allows you to check multiple statements.
!empty($_POST['fullname']) // Verify if the field name is not empty
AND isset($_POST['email']) // Is the email field being posted; it does not matter if it's empty or filled.
&& // This is the same as the AND in our statement; it allows you to check multiple statements.
!empty($_POST['email'])) // Verify if the field email is not empty
{
$fullname = mysql_real_escape_string($_POST['fullname']);
$email = mysql_real_escape_string($_POST['email']);
}
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)){
// Return Error - Invalid Email
$msg = 'The email you have entered is invalid, please try again.';
}else{
// Return Success - Valid Email
$msg = 'Your account has been created, <br /> please verify it by clicking the activation link that has been send to your email.';
}
$hash = md5(rand(0,1000)); // Generate random 32 character hash and assign it to a local variable.
$PIN = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable.
$to = $email; // Send email to our user
$subject = 'Signup | Verification'; // Give the email a subject
$from="[email protected]";
$message = 'Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by clicking the url below.
------------------------
echo $_POST["UserID"];
PIN: '.$PIN.'
------------------------
Please click this link to activate your account:
http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
'; // Our message above including the link
$headers = 'From:[email protected]' . "\r\n"; // Set from headers
mail($to, $subject, $message, $headers); // Send our email //Line 541
?>
<!-- stop PHP Code -->
</div>
**LOGIN.PHP**
<div id="wrap">
<!-- start PHP code -->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with UserID and PIN.
mysql_select_db("registrations") or die(mysql_error()); // Select registration database.
if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['PIN']) && !empty($_POST['PIN'])){
$UserID = mysql_escape_string($_POST['name']);
$PIN = mysql_escape_string(md5($_POST['PIN']));
$search = mysql_query("SELECT UserID, PIN, active FROM users WHERE UserID='".$UserID."' AND PIN='".$PIN."' AND active='1'") or die(mysql_error());
$match = mysql_num_rows($search);
if($match > 0){
$msg = 'Login Complete! Thanks';
}else{
$msg = 'Login Failed!<br /> Please make sure that you enter the correct details and that you have activated your account.';
}
}
?>
<!-- stop PHP Code -->
<?php
if(isset($msg)){ // Check if $msg is not empty
echo '<div class="statusmsg">'.$msg.'</div>'; // Display our message and add a div around it with the class statusmsg
} ?>
</div>
**VERIFY.PHP**
我已經有一個Web託管帳戶。但是,如何在用戶註冊電子郵件時通過我的雅虎電子郵件發送到用戶在註冊頁面中指定的任何電子郵件地址進行測試? – Kaos 2013-02-25 21:26:22
這是一個漫長的過程!請檢查該鏈接,這個例子中,你會準備好去。 http://www.phpeasystep.com/phptu/24.html – Richie 2013-02-25 22:12:04
謝謝,這是一個非常有用的鏈接。我假設到目前爲止,我的代碼沒有任何問題。(唯一不同的是,在你給我的鏈接中,有一個臨時數據庫,在單擊驗證電子郵件中的鏈接之後,註冊詳細信息將被存儲和傳輸。)我基本上只需要知道我是如何處理它是正確的以及有效 – Kaos 2013-02-25 23:09:26