注册后发送电子邮件验证

loo*_*mie 1 php sql email verification

我想,在我的网站上注册的用户必须首先激活他们的帐户,然后再使用它.问题是,我没有收到任何电子邮件到我的电子邮件测试帐户.

在我开始发布代码之前,问题是,我目前正在使用xampp在本地计算机上工作吗?

否则,这是代码片段

$random = substr(number_format(time() * rand(),0,'',''),0,10);
    $insertMailVerify = $this->db->prepare("INSERT INTO mailverify (mailAddress, token, datetime) VALUES (:mailAddress, :token, :date)");
    $insertMailVerify->execute(array(':mailAddress'=>$emailAddress,
                                     ':token'=>$random,
                                     ':date'=>$date));

    $to = $emailAddress;
    $subject = "Activating your Account";
    $body = "Hi, in order to activate your account please visit http://localhost/FinalYear/activation.php?email=".$emailAddress." and fill in the verification code $random";
    if(mail($to, $subject, $body))
    {
        echo ("<p>Message success</p>");
    }
    else {
        echo ("<p>Message fail</p>");
    }
Run Code Online (Sandbox Code Playgroud)

万一你想知道我从哪里拿$ emailAddress:这只是一个代码片段,我已经让软件回应了电子邮件地址,这是正确的.如果是这样的话,它甚至会出现"消息成功",但我仍然无法收到任何电子邮件.可能是什么问题呢?

小智 6

提交表单后,您可以使用代码或链接并将其发送到用户电子邮件ID

$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link <a href="verification.php">Verify.php?id='.$db_id.'&code='.$code.'</a>to activate  your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);

echo "An Activation Code Is Sent To You Check You Emails";
Run Code Online (Sandbox Code Playgroud)

来自TalkersCode.com的代码以获取完整的教程访问http://talkerscode.com/webtricks/account-verification-system-through-email-using-php.php