Parse error: syntax error, Unexpected '{' online 3

Asked

Viewed 60 times

-3

'Cause you’re making that mistake?

Parse error: syntax error, unexpected '{'  on line 3

Php code

<?php

if (isset($_POST['email'] && !empty($_POST['email'])){

$nome = addslashes($_POST['name']);
$email = addslashes($_POST['email']);
$mensagem = addslashes($_POST['mens']);

$toMe = "[email protected]";
$subject = "Contato - Douglas";
$body = "Nome: ".$nome. "\r\n".
        "Email: ".$email."\r\n".
        "Mensagem: ".$mens;

$header = "From: [email protected]"."\r\n"
    ."Reply-To: ".$email."\e\n"
    ."X=Mailer:PHP/"phpversion();

if(mail($toMe, $subject, $body, $header)){

    echo("Email enviado com sucesso!");

}else {

    echo("Email não pode ser enviado!");

    }

}

?>

Html Code

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">

    <title>Contato</title>



    <style type="text/css">

            body{font-family: Arial, Helvetica, sans-serif}
            .content{display: flex;justify-content: center}
            .contato{width: 100%; max-width: 500px;}
            .form{display: flex;flex-direction: column}
            .field{padding: 10px; margin-bottom: 15px; border: 1px solid #DDD; border-radius: 5px; font-family: Arial, Helvetica, sans-serif; font-size: 16px}
            textarea{height: 150px}

    </style>



</head>
<body>


    <section class= "content">

        <div class="contato">
            <h3>Formulário de Contato</h3>

            <form class="form" method="POST" action="./email.php"> 

                <input class="field" name="name" placeholder="Nome">

                <input class="field" name="email" placeholder="E-mail">

                <textarea class="field" name="mens" placeholder="Digite sua Mensagem Aqui!!">

                </textarea>

                <input class="field" type="submit" value="Enviar!">

            </form>


        </div>

    </section>


</body>
</html>
  • Not missing a parentheses in the if no ? if (isset($_POST['email']) && !empty($_POST['email'])){ And the "eçe" with cedilha, in the first line of your question, will also give error.

  • One parenthesis left to close your if isset.

  • It was bad at the beginning

1 answer

0


Empty already checks if your variable exists, so the code would look like this:

<?php
if (!empty($_POST['email'])) {

    $nome = addslashes($_POST['name']);
    $email = addslashes($_POST['email']);
    $mensagem = addslashes($_POST['mens']);

    $toMe = "[email protected]";
    $subject = "Contato - Douglas";
    $body = "Nome: ".$nome. "\r\n".
        "Email: ".$email."\r\n".
        "Mensagem: ".$mens;

        $header = "From: [email protected]"."\r\n"
        ."Reply-To: ".$email."\e\n"
        ."X=Mailer:PHP/" . phpversion();

    if (mail($toMe, $subject, $body, $header)) {
        echo("Email enviado com sucesso!");
    } else {
        echo("Email não pode ser enviado!");
    }
}
?>

Also missing was one . before the phpversion()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.