Solution 1 :

The isset function does not check if the variable is empty. An empty string (what your e-mail input will be if the input is left blank) is considered as set. Consult the type comparison table.

Instead, you should use empty to check if the e-mail field has a value:

if(!empty($_POST['Email'])){

Problem :

I have the following problem: Although I actually use “if isset” to check whether the variable contains a value, it is sufficient if only in $besteatigung has a value and the empty $ email is simply ignored. Can someone help me please?
(I am a beginner)

<html>
    <head>
    <link rel="stylesheet" href="style.css">
        <title>Newslatter Anmeldung</title>
        <meta charset="utf-8">
    </head>
    <body>
        <div>  
        <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
            <p>Ihre E-Mail adresse bitte: </p>
            <input type="email" name="Email">
            <p>Anrede: (optional)</p>
            <input type="radio" name="Geschlecht" value="Mann">
            <label for="Geschlecht">Mann</label><br>
            <input type="radio" name="Geschlecht" value="Frau">
            <label for="Geschlecht">Frau</label><br>
            <p>Vorname: (optional)</p>
            <input type="text" name="Vorname">
            <p>Nachname: (optional)</p>
            <input type="text" name="Nachname">
            <p><input type="checkbox" name="bestaetigung">hiermit bin ich einverstanden,<br> dass meine Daten elektronisch gespeichert werden,<br> damit mir die gewünschte Newsletter zugestellt werden kann ... <br>(gesetzliches Blahblah zum Datenschutz und Speicherung der Daten ....)</p>
            <input type="submit" value="Anmelden" name="submit">
        </form>
        </div>
    </body>
</html>
<?php
if(isset($_POST['submit'])){
    if(isset($_POST['Email'])){ 
        if(isset($_POST['bestaetigung'])){
            $Email = htmlspecialchars(stripslashes(trim($_POST['Email'])));
            $Geschlecht = $_POST['Geschlecht'];
            $Vorname = htmlspecialchars(stripslashes(trim($_POST['Vorname'])));
            $Nachname = htmlspecialchars(stripslashes(trim($_POST['Nachname'])));
            
            $date = date("syHjin");
            
            $file = fopen("nl-anwaerter.txt", "a");
            fwrite($file, "$Email");
            fwrite($file, "|");
            fwrite($file, "$Geschlecht");
            fwrite($file, "|");
            fwrite($file, "$Vorname");
            fwrite($file, "|");
            fwrite($file, "$Nachname");
            fwrite($file, "|");
            fwrite($file, "$date");
            fwrite($file, "n");
            fclose($file);
            
            $empaenger = "$Email";
            $betreff = "Ihre Newsletter Anmeldung";
            $from = "From: PHP mailer <[email protected]>rn ";
            $from .= "Reply-To: [email protected]";
            $from .= "Content-Type: text/htmlrn";
            $msg = "<h1>Newsletter Anmeldung</h1><br><p>Hallo $Name $Nachname um dich entgültig für den Nwesletter anzumelden Klicke bitte auf folgenden Linl: ";
            
            if(mail($empaenger,$betreff,$msg,$from)){
                echo "Eine E-Mail wurde erfolgreich an $Email gesendet, bitte klicke auf den Link in dieser um die Anmeldung zu bestätiegen";
            }
            
        }
    }
    
}
?>

Hello, I have the following problem: Although I actually use “if isset” to check whether the variable contains a value, it is sufficient if only in $besteatigung has a value and the empty $ email is simply ignored. Can someone help me please?
(I am a beginner)

Comments

Comment posted by Luca

Oh right, thank you very much. I could have figured it out myself 🙂

By