-2

I'm trying to make a form that mails the information to me. Here's my code.

PHP:

$to = "mosescu_b@yahoo.com";
$subject = "Comanda de Magneti";

$name = $_POST["nume"] . $_POST["prenume"];
$email = $_POST["email"];
$phone = $_POST["telefon"];
$adress = $_POST["adresa"];

$message = <<<EMAIL

Comanda de Magneti de la $name

Adresa de E-mail este $email    

Numarul de telefon este $phone

Adresa este $adress

EMAIL;

$header ="$email";

if($_POST){

mail($to, $subject, $message, $header);

$feedback = "Multumesc pentru comanda!"
}    

HTML

<div class="form-group">
        <form style="font-size: 1.25em; margin-left: 20px;" method="post" action="#">
            <label for="nume">Nume<span style="color: red;">*</span></label> <input name="nume" id="nume" class="form-control" type="text" placeholder="Nume" title="nume">
            <label for="prenume">Prenume<span style="color: red;">*</span></label> <input name="prenume" id="prenume" class="form-control" type="text" placeholder="Prenume" title="prenume">
            <label for="email">E-Mail</label><span style="color: red;">*</span><input name="email" id="email" class="form-control" type="email" placeholder="E-Mail" title="email">
            <label for="telefon">Numar Telefon</label><input name="telefon" id="telefon" class="form-control" type="number" placeholder="Numar Telefon" title="telefon">
            <label for="adresa">Adresa</label><span style="color: red;">*</span><input name="adresa" id="adresa" class="form-control" type="text" placeholder="Strada/Numar/Localitate/Judet" title="adresa"> <br />
            <input name="submit" class="btn-default" type="submit" value="Comanda!"></input>
        </form>
        <p id="feedback"><?php echo $feedback ?> </p>
</div>

The error I'm getting is :"Parse error: syntax error, unexpected '}' in C:\wamp64\www\Test\comanda-magneti.php on line 30"

Which is weird, since I'm very sure that the code wouldn't run properly without the curly bracket.

aynber
  • 22,380
  • 8
  • 50
  • 63
Blaze26
  • 201
  • 1
  • 3
  • 8
  • 1
    missing `;` before curly bracket – Markus Laire Aug 05 '16 at 18:10
  • possible duplicate of [PHP: “Notice: Undefined variable” and “Notice: Undefined index”](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Funk Forty Niner Aug 05 '16 at 18:23
  • ^ that, given the OP's new error (in an answer given below) when fixing the missing semi-colon. The question was off-topic by 2 accounts, even before the fix. – Funk Forty Niner Aug 05 '16 at 18:24

1 Answers1

2

Change this:

$feedback = "Multumesc pentru comanda!"

to

$feedback = "Multumesc pentru comanda!";

You forgot to add semi colon. Semicolon is act is line terminator in PHP and of course you can skip it for last line. But in this case you have closing curly braces after that.

Also please move if($_POST) to top as you are checking for it below and accessing POST properties above.

So something like:

if(isset($_POST)){
    $to = "mosescu_b@yahoo.com";
    $subject = "Comanda de Magneti";

    $name = (isset($_POST["nume"]) ? $_POST["nume"] : '')  . isset($_POST["prenume"]) ? $_POST["prenume"] : '' ;
    $email = isset($_POST["email"]) ? $_POST["email"];
    $phone = isset($_POST["telefon"]) ? $_POST["telefon"] : '';
    $adress = isset($_POST["adresa"]) ? $_POST["adresa"] : '';

    $message = <<<EMAIL

Comanda de Magneti de la $name

Adresa de E-mail este $email    

Numarul de telefon este $phone

Adresa este $adress

EMAIL;

    $header ="$email";

    mail($to, $subject, $message, $header);

    $feedback = "Multumesc pentru comanda!"
}  

Also if possible do necessary check for POST variable for required fields.

Anil Chauhan
  • 226
  • 1
  • 8
  • You know that an explained answer tends to attract (+) votes (that's if you're into that also). There is a reason as to why that semi-colon should be used in there. Unless you're not interested, then this would be considered as a very low-quality answer. Just a Stack protip ;-) Hint: http://php.net/manual/en/language.basic-syntax.instruction-separation.php – Funk Forty Niner Aug 05 '16 at 18:15
  • Ok that worked! Thanks for that. But now it says that "nume","prenume","email","telefon" and "adresa" are undefined. – Blaze26 Aug 05 '16 at 18:17
  • Ok, I have edit my answer, which also covers your query. @Fred-ii- I will take care of it. Thanks! – Anil Chauhan Aug 05 '16 at 18:29