用随机字符串生成器和MySQL验证电子邮件

时间:2013-12-28 08:50:12

标签: javascript php html mysql forms

我的电子邮件验证码有点问题。我尝试向用户发送唯一的密码ID。用于在用户名+密码旁边登录。

我使用随机字符串密钥生成器构建它:

<?php
function passFunc($len, $set = "") {
    $gen = "";
    for($i = 0; $i < $len; $i++) {
        $set = str_shuffle($set);
        $gen .= $set[0];
    }
    return $gen;
}
$passcode=passFunc(4, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
?>

我这样使用它:当用户提交表单时:

<form method="POST" action="" id="" name="register">
    Email address <input type="text" name="username" id="username placeholder="E-Mail adres" maxlenght="50"><p>
    Repeat Email address <input type="text" name="email" id="email" placeholder="Herhaal uw E-Mail adres"><p>
    Password <input type="password" name="password" id="password" placeholder="Wachtwoord"><p>
    First name <input type="text" name="voornaam" id="voornaam" placeholder="Voornaam" maxlenght="15"><p>  
    Lastname <input type="text" name="achternaam" id="achternaam" placeholder="Achternaam" maxlenght="20"><p>
    Telephone number:* <input type="text" name="telefoonnummer" id="telefoonnummer" placeholder="Telefoon nummer" maxlenght="14"><p>
    Company <input type="text" name="bedrijf" id="bedrijf" placeholder="Bedrijf" maxlenght="50"><p>
    <input type="hidden" name="passcode" id="passcode" value="<?php echo $passcode; ?>">
    <input type="submit" class="btn btn-success" value="Registreer">&nbsp;
    <input type="reset" class="btn btn-info" value="Reset formulier">
    <!-- Send email when successfully registered -->

关于这段代码,它将随机字符串显示在隐藏字段中,可以通过电子邮件发送:

<input type="hidden" name="passcode" id="passcode" value="<?php echo $passcode; ?>">

但是当我尝试使用此电子邮件表单发送时:

<?php
 $to = $_POST['username'];
 $subject = "Your account has been created";

 <!--- body of the email -->
 $body = $_POST['passcode'];
 $body = 'This is your passcode \n login at http://www.directofficesupport
 /login.php \n Regards, the Directofficesupport.com team.';
 <!--- end of email body -->

 $from = 'account@directofficesupport.com';
 (mail($to, $subject, $body, $form)) 
 ?>

它不起作用。

但有趣的是,当随机字符串在数据库中注册时。这确实有效,但电子邮件没有。

我无法让它工作D: 请帮忙。

此致 杰西

编辑:

嗯,但有一件事。你怎么把

$_POST['passcode'] 

在句子的中间 你需要这样做吗?

$body =  '\n This is your passcode: $_POST['passcode'] . \n login at http://www.directofficesupport
/login.php \n Regards, t
  • 杰西

2 个答案:

答案 0 :(得分:0)

<?php
$to = $_POST['username'];
$subject = "Your account has been created";

<!--- body of the email -->
$body = $_POST['passcode'] . '\n This is your passcode \n login at http://www.directofficesupport
/login.php \n Regards, the Directofficesupport.com team.';
<!--- end of email body -->

 $from = 'account@directofficesupport.com';
 (mail($to, $subject, $body, $form)) 
 ?>

答案 1 :(得分:0)

使用正确的转义字符串:

$body =  '\n This is your passcode: '. $_POST['passcode'] . '\n login at http://www.directofficesupport/login.php \n Regards, t...';

或广告.附加到原始字符串:

$body = $_POST['passcode'];
$body .= 'This is your passcode \n login at http://www.directofficesupport/login.php \n Regards, the Directofficesupport.com team.';
//----^