-2

I'm having a persisting problem with my php mail script and I can't seem to get to its root. Sorry if this is a stupid question but I'm just starting up with php.

I'm getting a syntax error on line 86 for "$email_message" here is the full php script:

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

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "office@medicaepv.ro";
    $email_subject = "Cerere Programare";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }


    // validation expected data exists
    if(!isset($_POST['nume']) ||
        !isset($_POST['prenume']) ||
        !isset($_POST['telefon']) ||
        !isset($_POST['adresa']) ||
        !isset($_POST['email'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }



    $first_name = $_POST['nume']; // required
    $last_name = $_POST['prenume']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telefon']; // required
    $comments = $_POST['textarea']; // not required
    $age = $_POST['varsta']; // not required
    $adresa = $_POST['adresa']; //not required
    $sex = $_POST['sex']; //not required
    $region = $_POST['judet']; //required
    $city = $_POST['oras']; //required
    $departament = $_POST['departament']; //required
    $date = $_POST['data']; //required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }

  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }

  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }

    $email_message = "Form details below.\n\n";


    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }



    $email_message .= "Nume: ".clean_string($first_name)."\n";
    $email_message .= "Prenume: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telefon: ".clean_string($telephone)."\n";
    $email_message .= "Varsta: ".clean_string($age)."\n";
    $email_message .= "Sex: ".clean_string($sex)."\n";
    $email_message .= "Adresa: ".clean_string($adresa)."\n";
    $email_message .= "Judet: ".clean_string($region)."\n";
    $email_message .= "Localitate: ".clean_string($city)."\n"
    $email_message .= "Departament: ".clean_string($departament)."\n";
    $email_message .= "Data: ".clean_string($date)."\n";
    $email_message .= "Mesaj: ".clean_string($comments)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>


Thank you for contacting us. We will be in touch with you very soon.

<?php

}
?>

And here is the form html:

</div>
            <div class="content">
                <div class="container padd-top padd-bottom">
                    <div class="text-center">
                        <h2>Formular Programare</h2>
                    </div>
                        <form action="formular.php" method="POST" class="about-form info-form">
                        <div class="info-heading-icon">
                            <h4>Date Personale</h4>
                        </div>
                        <ul class="row info">
                            <li class="col-sm-4">
                                <span class="form-title">Nume</span>
                                <input type="text" name="nume" class="form-part" />
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Prenume</span>
                                <input type="text" name="prenume" class="form-part" />
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Varsta</span>
                                <input type="text" name="varsta" class="form-part" />
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Sex</span>
                                <span class="info-holder">
                                    <select class="form-part" name="sex">
                                        <option>-Masculin-</option>
                                        <option>-Feminin-</option>

                                    </select><span class="info-arrow"> </span></span>
                            </li>
                            <li class="col-sm-8">
                                <span class="form-title">Adresa</span>
                                <input type="text" name="adresa" class="form-part" />
                            </li>

                            <li class="col-sm-4">
                                <span class="form-title">Judet</span>
                                <span class="info-holder">
                                    <select class="form-part" name="judet">
                                        <option>-Bucuresti Sector 1-</option>
                                        <option>-Bucuresti Sector 2-</option>
                                        <option>-Bucuresti Sector 3-</option>
                                        <option>-Bucuresti Sector 4-</option>
                                        <option>-Bucuresti Sector 5-</option>
                                        <option>-Bucuresti Sector 6-</option>
                                        <option>-Ilfov-</option>
                                        <option>-Altul-</option>

                                    </select><span class="info-arrow"> </span></span>
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Localitate</span>
                                <span class="info-holder">
                                    <select class="form-part" name="localitate">
                                        <option>-Bucuresti-</option>
                                        <option>-Chitila-</option>
                                        <option>-Voluntari-</option>
                                        <option>-Mogososoaia-</option>
                                        <option>-Altul-</option>
                                    </select> <span class="info-arrow"> </span></span>
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Telefon</span>
                                <input type="tel" name="telefon" class="form-part" />
                            </li>
                            <li class="col-sm-4">
                                <span class="form-title">Email</span>
                                <input type="email" name="email" class="form-part" />
                            </li>
                        </ul>
                        <div class="info-heading-icon two">
                            <h4>Date Programare</h4>
                        </div>
                        <ul class="row info">
                            <li class="col-sm-4">
                                <span class="form-title">Departament</span>
                                <span class="info-holder">
                                    <select class="form-part" name="departament">
                                        <option>-Endocrinologie-</option>
                                        <option>-Dermatologie-</option>
                                        <option>-Nutritie-</option>
                                        <option>-Diabet-</option>
                                        <option>-Gastroenterologie-</option>
                                        <option>-Investigatii de Laborator-</option>
                                    </select> <span class="info-arrow"> </span> </span>
                            </li>

                            <li class="col-sm-4">
                                <span class="form-title">Data Programarii</span>
                                <input type="text" name="data" class="form-part date-pick" />
                            </li>
                        </ul>
                        <div class="info-heading-icon three">
                            <h4>Cu ce te putem ajuta?</h4>
                        </div>
                        <ul class="row">
                            <li class="col-sm-6">
                                <span class="form-title">Problema Ta</span>
                                <textarea name="textarea" class="form-part info-message"></textarea>
                            </li>
                        </ul>
                        <div class="text-left">
                            <input type="submit" class="btn btn-submit" value="Trimite!" />
                        </div>
                        <div class="g-recaptcha" data-sitekey="6LexXiEUAAAAAPmMR_MYL6sDrjOvVZqWaXemb9dK"></div>
                    </form>
                </div>
            </div>

Please ask if there is anything else you need!

Thanks!

Gimy
  • 1
  • 1

1 Answers1

1

Your forgot a semi-colon ; after

$email_message .= "Localitate: ".clean_string($city)."\n"

In the future please check PHP Parse/Syntax Errors; and How to solve them?.

Edit: As Tobias F. said: you should use an IDE or editor which supports syntax-highlighting or use an online service like PHP Code Checker.

Community
  • 1
  • 1
Tom Udding
  • 2,264
  • 3
  • 20
  • 30
  • Thanks! I really didn't see that and I went over it several times. Sorry for the stupid question! – Gimy May 17 '17 at 06:35
  • 1
    You should use an ide or editor which supports syntax-highlighting, so you will see such errors in the future. – Tobias F. May 17 '17 at 06:38
  • 1
    A little addition to the comment of @TobiasF.; you can also use an online service like [PHP Code Checker](https://phpcodechecker.com). – Tom Udding May 17 '17 at 06:39