S
S
spandae2020-05-08 21:05:41
PHP
spandae, 2020-05-08 21:05:41

Syntax error, unexpected T_VARIABLE and why?

<?php
//print_r($_POST);
$email = $_POST['email'];
$message = $_POST['email'];

$Error = '';
if(trim($email == '')
    $Error = 'Введите ваш email';
else if(trim($message) == '')
  $Error =  'Введите сообщение';
else if(strlen($message) <10)
  $Error = 'Сообщение должно быть более 10 символов';
if($Error != ''){
  echo $Error;
  exit;
}
$subject ="=?utf-8?B?".base64_encode("Тестовое сообщение"). "?=";
$headers ="From: $email\r\nReplay-to: $email \r\nContent-type: text/html;charset=utf-8\r\n";
mail('[email protected]', $subject, $message, $headers);
?>

I get an error Syntax error, unexpected T_VARIABLE on the 7th line of the code, I can't figure out what's wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Edward, 2020-05-08
@spandae

spandae and so there is no error?

spoiler
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = $_POST['email'] ?? '';
    $message = $_POST['email'] ?? '';

    $error = '';

    if (trim($email) == ''){
        $error = 'Введите ваш email';
    } elseif (trim($message) == '') {
        $error = 'Введите сообщение';
    } elseif (strlen($message) < 10) {
        $error = 'Сообщение должно быть более 10 символов';
    }

    if ($error) {
        echo $error;
    } else {
        $subject = "=?utf-8?B?" . base64_encode("Тестовое сообщение") . "?=";
        $headers = "From: $email\r\nReplay-to: $email \r\nContent-type: text/html;charset=utf-8\r\n";
        mail('[email protected]', $subject, $message, $headers);
    }
}

R
Rsa97, 2020-05-08
@Rsa97

Because of the unclosed brace in trim

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question