【问题标题】:Email verification with random string generator and MySQL使用随机字符串生成器和 MySQL 进行电子邮件验证
【发布时间】:2013-12-28 08:50:11
【问题描述】:

我的电子邮件验证码有一点问题。我尝试向用户发送一个唯一的密码 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
  • 杰西

【问题讨论】:

  • 马上你就将 body = 设置为 POST PASSCODE 并在下一行将其设置为不同的值,也许你希望 .= 附加它
  • 也是显示信息,请举例说明如何显示信息和密码
  • 这是您的密码:'。 $_POST['passcode'] 。 '等

标签: javascript php html mysql forms


【解决方案1】:
<?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)) 
 ?>

【讨论】:

    【解决方案2】:

    使用正确的转义字符串:

    $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.';
    //----^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 2021-10-23
      • 2019-02-09
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多