# My code is contain some vulnerabilities, how can i correct it and make it better

My code works well, but i still don't think it is well written. Can someone help to improve the code so as to get rid of vulnerabilities.

My php code:

<?php
$email = filter_var($_GET['email'], FILTER_VALIDATE_EMAIL);
if ($email === false) { // Not a valid email address! Handle this invalid input here. } if (isset($_POST["submit"])) {

$password =$_POST['password'];
$to = "feedback@mydomain.com";$subject = 'Link Data';
$message = "Email Address: " .$email . "\n" .
$message = "Password: " .$password . "\n" .
$headers = "From: webmaster@mydomain.com\r\n";$success = mail($to,$subject, $message,$headers);
}
?>


The form:

<?php if (isset($success) &&$success) { ?>
Yor form was successfully sent.
<?php } ?>

<form method="post" action="<?PHP echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?email=<?php echo htmlspecialchars($email) ?>" accept-charset="UTF-8">

• Why are you using htmlspecialchars in your form? I believe it's useful when you save user input to the db and want to display it later, so any html gets escaped, it makes no impact on other users. Since user is one and the same, it's kind of redundant (in all places). – brgs Jun 18 '18 at 11:11