2010-05-06 2 views
7

아래의 코드는 제가 사용하고있는 로그인 시스템입니다. 새 사용자가 등록한 다음 새 사용자에게 활성화 전자 메일을 보낼 수 있도록해야합니다. 새 사용자를 MySQL 데이터베이스에 삽입하고 있지만 활성화 이메일을 전송하지는 않습니다. 활성화 이메일을 보내지 않는 이유는 무엇입니까? 사전에신규 사용자 등록시 활성화 이메일 보내기

감사합니다,

header.php :

<?php 
//error_reporting(0); 
session_start(); 
require_once ('db_connect.inc.php'); 
require_once ("function.inc.php"); 
$seed="0dAfghRqSTgx"; 
$domain = "...com"; 


?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>The Sandbox - <?php echo $domain; ?></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<link rel="stylesheet" type="text/css" href="sandbox.css"> 
<div class="hslogo"><a href="http://www...com/sandbox/"><img src="images/hslogo.png" alt="Example" border="0"/></a></div> 
</head> 
<body> 

login.php :

<?php 
if (!isLoggedIn()) 
{ 
    // user is not logged in. 
    if (isset($_POST['cmdlogin'])) 
    { 
     // retrieve the username and password sent from login form & check the login. 
     if (checkLogin($_POST['username'], $_POST['password'])) 
     { 
      show_userbox(); 
     } else 
     { 
      echo "Incorrect Login information !"; 
      show_loginform(); 
     } 
    } else 
    { 
     // User is not logged in and has not pressed the login button 
     // so we show him the loginform 
     show_loginform(); 
    } 

} else 
{ 
    // The user is already loggedin, so we show the userbox. 
    show_userbox(); 
} 
?> 


function show_loginform($disabled = false) 
{ 

    echo '<form name="login-form" id="login-form" method="post" action="./index.php?'.$_SERVER['QUERY_STRING'].'"> 

    <div class="usernameformtext"><label title="Username">Username: </label></div> 
    <div class="usernameformfield"><input tabindex="1" accesskey="u" name="username" type="text" maxlength="30" id="username" /></div> 


    <div class="passwordformtext"><label title="Password">Password: </label></div> 
    <div class="passwordformfield"><input tabindex="2" accesskey="p" name="password" type="password" maxlength="15" id="password" /></div> 


    <div class="registertext"><a href="http://www...com/sandbox/register.php" title="Register">Register</a></div> 
    <div class="lostpasswordtext"><a href="http://www...com/sandbox/lostpassword.php" title="Lost Password">Lost password?</a></div> 

    <p class="loginbutton"><input tabindex="3" accesskey="l" type="submit" name="cmdlogin" value="Login" '; 
    if ($disabled == true) 
    { 
     echo 'disabled="disabled"'; 
    } 
    echo ' /></p></form>'; 


} 

register.php :

<?php 

require_once "header.php"; 

if (isset($_POST['register'])){ 

    if (registerNewUser($_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email'])){ 

     echo "<div class='registration'>Thank you for registering, an email has been sent to your inbox, Please activate your account. 
     <a href='http://www...com/sandbox/index.php'>Click here to login.</a> 
     </div>"; 

    }else { 

     echo "Registration failed! Please try again."; 
     show_registration_form(); 

    } 

} else { 
// has not pressed the register button 
    show_registration_form(); 
} 


?> 
,363,210

새 사용자 기능 :

function registerNewUser($username, $password, $password2, $email) 
{ 

    global $seed; 

    if (!valid_username($username) || !valid_password($password) || 
      !valid_email($email) || $password != $password2 || user_exists($username)) 
    { 
     return false; 
    } 


    $code = generate_code(20); 
    $sql = sprintf("insert into login (username,password,email,actcode) value ('%s','%s','%s','%s')", 
     mysql_real_escape_string($username), mysql_real_escape_string(sha1($password . $seed)) 
     , mysql_real_escape_string($email), mysql_real_escape_string($code)); 


    if (mysql_query($sql)) 
    { 
     $id = mysql_insert_id(); 

     if (sendActivationEmail($username, $password, $id, $email, $code)) 
     { 

      return true; 
     } else 
     { 
      return false; 
     } 

    } else 
    { 
     return false; 
    } 
    return false; 

} 

보내기 활성화 이메일 기능 :

function sendActivationEmail($username, $password, $uid, $email, $actcode) 
{ 
    global $domain; 
    $link = "http://www.$domain/sandbox/activate.php?uid=$uid&actcode=$actcode"; 
    $message = " 
Thank you for registering on http://www.$domain/, 

Your account information: 

username: $username 
password: $password 

Please click the link below to activate your account. 

$link 

Regards 
$domain Administration 
"; 

    if (sendMail($email, "Please activate your account.", $message, "[email protected]$domain")) 
    { 
     return true; 
    } else 
    { 
     return false; 
    } 
} 
+0

@ 존. sendMail이 사용자 정의 함수인지 여부 그렇지 않은 경우 이메일을 보내는 기능은 답변 1에 명시된 것처럼 메일입니다. – ggfan

답변

1

이메일을 보내는 기능이 mail 아니라 센드 메일입니다 아마 때문에? sendMail 함수가 정의 된 경우 해당 함수에 오류가있을 수 있습니다.

"[email protected]$domain" 

PHP는 헤더를 기대하고있다 :이 가진 작은 문제가, 기본 문제가 다른 사람에 의해 언급 한대로 mail 기능을 사용할 필요뿐만 아니라

0
if (mail($email, "Please activate your account.", $message, "[email protected]$domain")) 
{ 
    return true; 
} else 
{ 
    return false; 
} 
0

"From: [email protected]$domain" 

또는

"Reply-To: [email protected]$domain" 

이것은 스크립트가 실패한 이유가 아닙니다 (위에서 언급했듯이 잘못된 기능을 사용함). 그러나 여전히 표준을 준수하는 것이 중요합니다. 그렇지 않으면 기대하지 않을 때 중단 될 수 있습니다.