jjzjj

PHP 注册和登录表单&电子邮件验证/邮件服务器设置

coder 2024-05-03 原文

我在一个小型网站上工作,该网站要求用户注册一个帐户,之后会向他们发送一封电子邮件,其中包含验证帐户的详细信息。单击验证电子邮件中的链接后,帐户应该处于事件状态并且用户应该能够登录。 我提供了 registration.php(注册)、login.php(登录)和 verify.php(验证帐户激活)的 3 个 PHP 片段 !!我正在使用 WAMP 服务器创建数据库并根据表

注意:这是我在注册页面上收到的唯一错误。

警告:mail():无法通过“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 C:\wamp\www\ONLINE BANKING 中的 ini_set()\registration.php 第 541 行

目前我有几个问题: 1. 我正在使用 hmailserver,但我不确定如何设置它 2. 我需要监控用户何时被添加到数据库中(我假设这只是在点击电子邮件验证链接之后)

请告诉我我做错了什么以及如何解决

**REGISTRATION.PHP**

     <div id="wrap">
                <!-- start PHP code -->
                <?php

                    mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with root .
                    mysql_select_db("registrations") or die(mysql_error()); // Select registration database.

                    $email="";

                    if( isset($_POST['fullname']) // Is the name field being posted; it does not matter whether it's empty or filled.  
            && // This is the same as the AND in our statement; it allows you to check multiple statements.  
            !empty($_POST['fullname']) // Verify if the field name is not empty 
            AND isset($_POST['email']) // Is the email field being posted; it does not matter if it's empty or filled.  
            && // This is the same as the AND in our statement; it allows you to check multiple statements.  
            !empty($_POST['email']) ) // Verify if the field email is not empty   
              {

                        $fullname = mysql_real_escape_string($_POST['fullname']);
                        $email = mysql_real_escape_string($_POST['email']);

                        }
                        if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)){
                            // Return Error - Invalid Email
                            $msg = 'The email you have entered is invalid, please try again.';
                        }else{
                            // Return Success - Valid Email
                            $msg = 'Your account has been created, <br /> please verify it by clicking the activation link that has been send to your email.';
                            }

                            $hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.

                            $PIN = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable.

        $to      = $email; // Send email to our user  
        $subject = 'Signup | Verification'; // Give the email a subject  
        $from="info@bfs.com";
        $message = 'Thanks for signing up! 
        Your account has been created, you can login with the following credentials after you have activated your account by clicking the url below. 
        ------------------------ 
        echo $_POST["UserID"];
        PIN: '.$PIN.' 
        ------------------------ 
        Please click this link to activate your account: 
        http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.' 
        '; // Our message above including the link  
        $headers = 'From:noreply@yourwebsite.com' . "\r\n"; // Set from headers  
        mail($to, $subject, $message, $headers); // Send our email  //Line 541

                ?>
                <!-- stop PHP Code -->   


            </div>

**LOGIN.PHP**
<div id="wrap">
        <!-- start PHP code -->
        <?php

            mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with UserID and PIN.
            mysql_select_db("registrations") or die(mysql_error()); // Select registration database.

            if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['PIN']) && !empty($_POST['PIN'])){
                $UserID = mysql_escape_string($_POST['name']);
                $PIN = mysql_escape_string(md5($_POST['PIN']));

                $search = mysql_query("SELECT UserID, PIN, active FROM users WHERE UserID='".$UserID."' AND PIN='".$PIN."' AND active='1'") or die(mysql_error()); 
                $match  = mysql_num_rows($search);

                if($match > 0){
                    $msg = 'Login Complete! Thanks';
                }else{
                    $msg = 'Login Failed!<br /> Please make sure that you enter the correct details and that you have activated your account.';
                }
            }


        ?>
        <!-- stop PHP Code -->
        <?php 
            if(isset($msg)){ // Check if $msg is not empty
                echo '<div class="statusmsg">'.$msg.'</div>'; // Display our message and add a div around it with the class statusmsg
            } ?>

    </div>

**VERIFY.PHP**

最佳答案

您必须设置您的服务器以发送邮件

set mail function in php.ini file to sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t" if you use something like xampp
and then
set senmail.ini
smtp_server=smtp.gmail.com //example

smtp_port=587
auth_username=YourMail@gmail.com
auth_password=YourMailPass

在你的情况下,你有 wamp 服务器,你应该配置这个服务器来发送邮件,正如我所说的 xampp 示例

关于PHP 注册和登录表单&电子邮件验证/邮件服务器设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15076584/

有关PHP 注册和登录表单&电子邮件验证/邮件服务器设置的更多相关文章

  1. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  2. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  5. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  6. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  7. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  8. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  9. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  10. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

随机推荐