2012-04-28 26 views
0

我剛剛開始構建,以便您收到一封電子郵件給他, 因此,它意味着批准用戶電子郵件,然後才能進入頁面。郵件問題到數據庫

if(!isset($user_found)) { 
    //sende email til brugere 
    $code = rand(111111111, 999999999); 
    //sendere info til brugere. 
    $to = $email; 
    $subject = "Activate din brugere - .....dk"; 
    $headers = "From: [email protected]"; 
    //indhold til email 
    $body = "Hej"; 

    if(empty($errors)) 
    { 
     if ($stmt = $mysqli->prepare('INSERT INTO `brugere` (`email`, `password`) VALUES (?, ?)')) { 
      /* Bind parametre */ 
      $stmt->bind_param('ss', $email, $password); 

      /* Sæt værdier på parametrene */ 
       $email = $_POST["email"]; 
      $password = sha1($_POST["password"]); 

      $stmt->execute(); 
      /* Luk statement */ 
      $stmt->close(); 

      echo "<div id=\"box\"><ul><li>Godkendt brugere</li></ul></div>"; 

     } else { 
      /* Der er opstået en fejl */ 
      echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error; 
     } 
    } 
} 

正是這樣,$代碼必須做一個邊緣代碼,以便用戶做一些事情之後的鏈接。

<?php 

if(!empty($_POST)) 
{    
    if ($stmt = $mysqli->prepare('SELECT * FROM `brugere` WHERE `email` = ?')) { 
     $stmt->bind_param('s', $email); 
     $email = $_POST['email']; 
     $stmt->execute(); 
     $stmt->store_result(); 
     $count = $stmt->num_rows; 
     $stmt->close(); 
     if ($count > 0) 
     { 
      $user_found = 1; 
     } 
    } 
    else { 
     /* Der er opstået en fejl */ 
     echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error; 
    } 
    if(!isset($user_found)) { 

     //sendere info til brugere. 
     $to = $email; 
     $subject = "Activate din brugere - .....dk"; 
     $headers = "From: [email protected]"; 
     //indhold til email 
     $body = "test"; 


     if(empty($errors)) 
     { 
      if ($stmt = $mysqli->prepare('INSERT INTO `brugere` (`email`, `password`, `code`) VALUES (?, ?, ?)')) { 
       /* Bind parametre */ 
       $stmt->bind_param('ss', $email, $password, $code); 

       /* Sæt værdier på parametrene */ 
       $email = $_POST["email"]; 
       $password = sha1($_POST["password"]); 
       $code; 

       $stmt->execute(); 
       /* Luk statement */ 
       $stmt->close(); 

       echo "<div id=\"box\"><ul><li>Godkendt brugere</li></ul></div>"; 

      } else { 
       /* Der er opstået en fejl */ 
       echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error; 
      } 
     } 
    } 
    else { 
     echo "<div id=\"box\"><ul><li>Der findes allerede en bruger med denne mail</li></ul></div>"; 
    } 
} 

?> 

這是我的代碼看起來像,

是我想出來的這是$代碼只是內部的數據庫,並會發送電子郵件給用戶...

詢問是否這裏有更多要了解它。

畢竟提出問題;

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

// message 
$message = ' 
<html> 
<head> 
    <title>Birthday Reminders for August</title> 
</head> 
<body> 
    <p>Here are the birthdays upcoming in August!</p> 
    <table> 
    <tr> 
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
    </tr> 
    <tr> 
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
    </tr> 
    <tr> 
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td> 
    </tr> 
    </table> 
</body> 
</html> 
'; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 
?> 

如何我這樣做只是爲了使用電子郵件來進入$到=「[email protected]

+0

什麼ben ??,我不能顯示它..???? – 2012-04-28 16:23:22

+0

http://php.net/mail? – 2012-04-28 16:30:19

+0

我認爲你應該使用庫來代替。檢查了這個http://swiftmailer.org/ – Songo 2012-04-29 11:37:32

回答

0

首先它會更好,如果你可以用英文寫的輸出。

在郵件發送的查詢字符串像

yourpage.php?USER = someuserid &碼= randomcode

只是檢查頁面用戶是否通過你提供的查詢字符串或不來了。如果他直接將他發送到錯誤頁面。如果他然後檢查你使用rand函數創建的代碼。如果存在,則在頁面中顯示內容。

代碼可能會按照這種方式。

<?php 
if(empty($error)) 
{ 
show_content(); 
} 
?> 

或者什麼都可以將用戶重定向到任何你想要的頁面。

檢查查詢字符串的代碼。

<?php 
if(!isset($_GET['qstring'])) // qstring for query string name 
{ 
// redirect to error page 
} 
else 
{ 
$qstring = $_GET['qstring']; 


//$res_code= mysql_query()........... (result of) 
//check for availability of your random code and the userid in your database table\ 
if(mysql_num_rows($res_code) > 0) 
{ 
show_content(); 
} 
else 
{ 
//again redirect to error page or index page. 
} 
} 
?> 

如果代碼可用,則顯示的內容。你可以使用switch case而不是if。這取決於你。

希望這可以幫助你的朋友。

+0

對不起,但我是閱讀障礙, 但我想從這裏做,你會發送一封電子郵件給用戶。 – 2012-04-28 17:12:41