-2

I have no idea why this code isn't working. It should be right, but every time I test it the PHP file gives an "unexpected } on line 20".

PHP:

<?php

if (isset($_POST["submit"])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['InputMessage'];

    $from = 'website.com'; 
    $to = 'email@email.com'; 
    $subject = 'Subject';

    $body = "From: $name\n E-Mail: $email\n Messagge\n $message";

    if (mail ($to, $subject, $body, $from)) {
    $result='<div class="alert alert-success">Thanks! We\'ll reply as soon as possible.</div>';
    } else {
    $result='<div class="alert alert-danger">Sorry but there was error, try again later</div>';
    }
}  //this is line 20 on the original file
?>

HTML:

<form role="form" method="POST" action="contact.php">
    <div class="form-group">
       <input type="text" class="form-control" id="user_name" placeholder="Your name" name="name">
    </div>
    <div class="form-group">
       <input type="email" class="form-control" id="your_email" placeholder="Your email" name="email" required>
    </div>
    <div class="form-group">
       <textarea name="InputMessage" id="user_message" class="form-control" rows="5" required></textarea>
    </div>

    <button type="submit" class="btn medium" name="submit">Let us know</button>
</form> 

If I remove it then I get an unexpected enf of file. I don't know what to do, I'm really new with PHP.

EDIT: I checked the thread for which this has been flagged as duplicate, but it didn't solve anything. For the "unexpected }" it simply says that I probably forgot to open it, but I doubled checked the curly braces and they look ok.

antipopp
  • 409
  • 1
  • 3
  • 14

1 Answers1

2

You'll have to fix your string since it has a single quote inside

'<div class="alert alert-success">Thanks! We\'ll reply as soon as possible.</div>'
Yair.R
  • 795
  • 4
  • 11
  • I actually translated that string since english is not the website language, this are the original strings. `'
    Ci dispiace, ma c\'&eacute stato un problema. Riprova pi&ugrave tardi
    '; ` `'
    Grazie! Ti ricontatteremo al pi&ugrave presto
    ';`
    – antipopp May 18 '16 at 15:06
  • This not helping me much... give me the full string as you trying to do.. – Yair.R May 18 '16 at 16:17