0

I want to make a website(small one) I want to make people able to send write their username and password to be sent to my email(because I am still developing a database and I want to make sure if it will work or not)

I tried to put php in the same file as html but when it processes the code it just shows the code but dooesn't run it

<html>
<head>
    <?php
    if(isset)($_POST['name']) && isset($_POST['email'])) {
        $pass = $_POST['pass'];
        $email = $_POST['email'];
        $to = 'omar12haytham@gmail.com';
        $subject = 'Password';
        $body = '<html>
                <body>
                 <h2>Hello</h2>
                 <hr>
                 <p>Email<br>' . $email . '</p>
                 <p>Password<br>' . $pass . '</p>
                </body>
            </html>';
        //headers
        $headers =  "From: ".$name." <".$email.">\r\n";
        $headers .= "Reply-To: ".$email."\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=utf-8";
        //send
        $send = mail($to, $subject, $body, $headers);
        if ($send) {
            echo '<br>';
            echo 'Your email or password is incorrect';


        } else {
            echo error;
        }
    }
    </head>
    ?>
<body>
<form action="" method="post">
    <input type="text" name="name" placeholder="Write your email"><br>
    <input type="password" name="email" placeholder="Write your password"><br>
    <button type="submit">Log in</button>
</form>
</body>
</html>

I expected it to send me an email but it doesn't must I launch it? I am testing it as .html file not as a working website.

aynber
  • 22,380
  • 8
  • 50
  • 63
  • 2
    BASIC Syntax Bench check - `if(isset)($_POST['name'])` ????? – RiggsFolly Feb 14 '19 at 18:45
  • `$headers = "From: ".$name." <".$email.">\r\n";` looks a bit dodgy yo me also. Start by kjeeping it simple – RiggsFolly Feb 14 '19 at 18:48
  • 1
    Depending on your server setup, you may have to name the file *.php instead of *.html. Also, never send passwords in emails. If you need to debug something, you can write output to a local log file. – Alex Howansky Feb 14 '19 at 18:48
  • 2
    You have all of your PHP code, complete with echoes, in your `` section. Your errors may not show to the user there. HTML files and files opened directly in a browser will not parse the PHP, so nothing will be sent. – aynber Feb 14 '19 at 18:48
  • _I am testing it as .html file_ PHP Code will not (normally) run from within a .html file. – RiggsFolly Feb 14 '19 at 18:52

1 Answers1

-2

This piece of code doesn't work: isset)($_POST['name']) use instead if(isset($_POST["name"]))

Martys
  • 20
  • 6