我的电子邮件验证码有一个小问题。我尝试向用户发送唯一的密码 ID。用于在用户名+密码旁边登录。
我使用随机字符串 key 生成器构建了它:
<?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">
<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
- 杰西
最佳答案
<?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))
?>
关于javascript - 使用随机字符串生成器和 MySQL 进行电子邮件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20812681/