-3

I'm new to PHP, so i dont know a whole lot about it.

I created a script, with some help from a tutorial, but every time i run it on my website it creates an error.

Unexpected ")" in row 19. I've tried searching for an answer, but haven't found any solution.

The script looks like this: http://pastebin.com/0ANLFQTr

Mathias
  • 1
  • 2
  • 1
    I don't see a problem in the script. Are you sure it's line 19 of this script? Please post the full error text and tell us what this script is called. It's also recommended on StackOverflow to paste your code, not link to it. – BeetleJuice Jul 13 '16 at 06:18
  • 2
    Agreed. No error in this script. Just no declaration of $errName and $errEmail (missing). – Jerry Jul 13 '16 at 06:24
  • Edit your question and add the code there. With a reference to the original tutorial. – Progrock Jul 13 '16 at 06:26
  • @u_mulder I've already read that one, but didnt find the solution to my problem. – Mathias Jul 13 '16 at 06:27

2 Answers2

0

That code which you show is fine.

Try it:

<?php
if (isset($_POST["submit"])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $from = 'Servicemodul Kontaktform';
    $to = 'mat.joe@outlook.dk';
    $subject = 'Besked fra Servicemodul Kontaktform';
    $errName = false;
    $errEmail = false;

    $body = "From: $name\n E-mail: $email\n";

    if (!isset($_POST['name'])) {
        $errName = "Udfyld venligst med dit navn";
    }

    if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errEmail = 'Angiv venligst en gyldig E-mail';
    }
    if (!$errName && !$errEmail) {
        if (mail($to, $subject, $body, $from)) {
            $result = '<div class="alert alert-success"> Tak, vi sender dig en mail snarest</div>';
        } else {
            $result = '<div class="alert alert-danger">Der var et problem da vi skulle sende din mail, prøv igen senere</div>';
        }
    }
}
?>
rad11
  • 1,561
  • 3
  • 15
  • 30
0
    <?php
    if  (isset($_POST["submit"])){
$name   =   $_POST['name'];
$email  =   $_POST['email'];
$from   =   'Servicemodul Kontaktform';
$to     =   'mat.joe@outlook.dk';
$subject    =   'Besked fra Servicemodul Kontaktform';

$body   =   "From: $name\n E-mail: $email\n";

if  (!$_POST['name']){
    $errName    =   "Udfyld venligst med dit navn";
}

if  (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))   {
$errEmail   =   'Angiv venligst en gyldig E-mail';
}

if (!isset($errName) && !isset($errEmail)) {
    if  (mail   ($to,    $subject,    $body,   $from))  {
        $result='<div class="alert alert-success"> Tak, vi sender dig en mail snarest</div>';
    } else {
        $result='<div class="alert alert-danger">Der var et problem da vi skulle sende din mail, prøv igen senere</div>';
    }
}
    }
?>
Kruti Aparnathi
  • 175
  • 1
  • 11