注册后如何发送邮件

发布于 2024-10-09 07:50:58 字数 72 浏览 0 评论 0原文

当有人在网站上注册后,通常会向他的邮件帐户发送一封邮件。但是要生成此链接或可以在此链接中放置哪些信息以便可以使用它来激活用户帐户?

After that someone registers in a site, a mail is usually sent to his mail account. But to generate this link or what info can be placed in this link so that it can be used to activate the user account??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

简美 2024-10-16 07:50:58

您可以放置​​任何可以识别有效用户的内容

1- 哈希值

2- 加密字符串

3- Guid

,当用户单击链接时,您可以验证该值。

you can place any thing which can identify a valid user

1- A Hash Value

2- An Encrypted String

3- A Guid

and when user clicks on the link , you can validate the value.

飘落散花 2024-10-16 07:50:58

检查这部分代码:

生成代码和电子邮件:

/* if $acces = 0 everything is perfect so the system send a confirmation mail */ 
                                if($acces == 0) 
{ 
    print("<br>A mail has been send to " . $mail . "<br><br>") ; 

    /* prepare the vars */ 
    $activ = $user . $pass ; 
    $code = md5($activ) ; 
    /* to how send to mail */ 
    $to = $mail ; 
    /* prepare the subject */ 
    $subject = "You need to confirm you registration to " . $_SERVER['HTTP_HOST'] ; 
    /* start writing the message */ 
    $message = "Hello " . $user . ",\r\n\r\n" ; 
    $message .= "Thank you for registering at " . $_SERVER['HTTP_HOST'] . " Your account is created and must be activated before you can use it.\r\n" ;
    $message .= "To activate the account click on the following link or copy-paste it in your browser :\r\n\r\n" ; 
    $message .= "http://" . $_SERVER['HTTP_HOST'] . "/~carron/registration/register_send.php?user=" . $user . "&activation=" . $code . "\r\n\r\n" ; 
    $message .= "After activation you may login to http://" . $_SERVER['HTTP_HOST'] . " using the following username and password:\r\n\r\n" ; 
    $message .= "Username - " . $user . "\r\nPassword - " . $pass . "\r\n" ; 

    /* To send HTML mail, you can set the Content-type header. */ 
    $headers  = "MIME-Version: 1.0"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1"; 

    /* set up additional headers */ 
    $headers .= "To: " . $to . "<br>\n" ; 
    $headers .= "From: " . $from . $addmail ; 

    /* writing data in the base */ 
    $query = "INSERT INTO registration (user, pass, activ, mail) VALUES ('$user', '$pass', '$code', '$mail') ;" ; 

    $result = mysql_query($query, $db); 

    if ($result == false) 
        die("Failed " . $query); 
    else 
        { 
            /* everything went well so we can mail it now */ 
            mail($to, $subject, $message, $headers); 
        } 
} 

检查激活:

/* controle if the validation link is right */ 
$x = 0 ; 

$query = "SELECT user, pass, activ, mail FROM registration WHERE user = '" . $username . "';" ; 

$result = mysql_query($query, $db); 

if ($result == false) die("Failed " . $query); 


while ($fields = mysql_fetch_row($result)) 
        { 
         for ($i=0, $max=sizeof($fields) ; $i < $max ; $i++) 
                { 
                    $tmp[$i] = $fields[$i] ; 
                } 

         /* the activation link is right so we can update 
         the datas in the data base */ 
         if($activation == $tmp[2] AND $username == $tmp[0]) 
            { 
                $x = 1 ; 
                $query2 = "UPDATE registration SET activated = '1' WHERE user = '" . $username . "' AND activ = '" . $activation . "' ;" ; 

                $result2 = mysql_query($query2, $db); 

                if ($result2 == false) 
                    die("Failed " . $query2); 
            } 
         else 
            $x = -1 ; 
        } 

/* give a confirmation message to the user */ 
if($x == 1) 
    print($username . " your activation has been done perfectly<br> Thank you...") ; 
else 
    print($username . " your activation has not been done corectly<br> Please try again later...") ; 

来自 PHPclasses.org 的脚本

Check this part of code:

Generate code and e-mail:

/* if $acces = 0 everything is perfect so the system send a confirmation mail */ 
                                if($acces == 0) 
{ 
    print("<br>A mail has been send to " . $mail . "<br><br>") ; 

    /* prepare the vars */ 
    $activ = $user . $pass ; 
    $code = md5($activ) ; 
    /* to how send to mail */ 
    $to = $mail ; 
    /* prepare the subject */ 
    $subject = "You need to confirm you registration to " . $_SERVER['HTTP_HOST'] ; 
    /* start writing the message */ 
    $message = "Hello " . $user . ",\r\n\r\n" ; 
    $message .= "Thank you for registering at " . $_SERVER['HTTP_HOST'] . " Your account is created and must be activated before you can use it.\r\n" ;
    $message .= "To activate the account click on the following link or copy-paste it in your browser :\r\n\r\n" ; 
    $message .= "http://" . $_SERVER['HTTP_HOST'] . "/~carron/registration/register_send.php?user=" . $user . "&activation=" . $code . "\r\n\r\n" ; 
    $message .= "After activation you may login to http://" . $_SERVER['HTTP_HOST'] . " using the following username and password:\r\n\r\n" ; 
    $message .= "Username - " . $user . "\r\nPassword - " . $pass . "\r\n" ; 

    /* To send HTML mail, you can set the Content-type header. */ 
    $headers  = "MIME-Version: 1.0"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1"; 

    /* set up additional headers */ 
    $headers .= "To: " . $to . "<br>\n" ; 
    $headers .= "From: " . $from . $addmail ; 

    /* writing data in the base */ 
    $query = "INSERT INTO registration (user, pass, activ, mail) VALUES ('$user', '$pass', '$code', '$mail') ;" ; 

    $result = mysql_query($query, $db); 

    if ($result == false) 
        die("Failed " . $query); 
    else 
        { 
            /* everything went well so we can mail it now */ 
            mail($to, $subject, $message, $headers); 
        } 
} 

Check activation:

/* controle if the validation link is right */ 
$x = 0 ; 

$query = "SELECT user, pass, activ, mail FROM registration WHERE user = '" . $username . "';" ; 

$result = mysql_query($query, $db); 

if ($result == false) die("Failed " . $query); 


while ($fields = mysql_fetch_row($result)) 
        { 
         for ($i=0, $max=sizeof($fields) ; $i < $max ; $i++) 
                { 
                    $tmp[$i] = $fields[$i] ; 
                } 

         /* the activation link is right so we can update 
         the datas in the data base */ 
         if($activation == $tmp[2] AND $username == $tmp[0]) 
            { 
                $x = 1 ; 
                $query2 = "UPDATE registration SET activated = '1' WHERE user = '" . $username . "' AND activ = '" . $activation . "' ;" ; 

                $result2 = mysql_query($query2, $db); 

                if ($result2 == false) 
                    die("Failed " . $query2); 
            } 
         else 
            $x = -1 ; 
        } 

/* give a confirmation message to the user */ 
if($x == 1) 
    print($username . " your activation has been done perfectly<br> Thank you...") ; 
else 
    print($username . " your activation has not been done corectly<br> Please try again later...") ; 

Script from PHPclasses.org

绻影浮沉 2024-10-16 07:50:58

这个想法是有一个只有电子邮件收件人知道的链接。因此,当在您的网站上访问该链接时,您知道有人已阅读您发送的电子邮件并单击该链接,因此您可以假设注册者和阅读该电子邮件的人是同一个人。

因此,您只需要一个不易被猜到的链接。随机选择一些内容(并将其记录在用户的个人资料中)或散列用户名+种子或其他内容。

The idea is to have a link that only the recipient of the email knows. So when that link is visited on your site, you know that someone has read the email you sent and clicked on the link and so you can presume that the person who registered and the person who read the email are the same.

As such, you just need a link that can't be easily guessed. Pick something random (and record it in the user's profile) or hash the user name + a seed, or something.

躲猫猫 2024-10-16 07:50:58

当用户注册时,您可以使用uniqid()创建激活码并存储在数据库中。然后在邮件中提供一个链接,例如:http://....../activate.php?code=[uniqid()]
activate.php中,您可以从数据库读取激活代码并检查它。

When user registered, you can use uniqid() to create an activate code and stored in database. Then in mail, give a link like: http://....../activate.php?code=[uniqid()]
In activate.php, you can read activate code from database and check it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文