phphtmlmail-form

cant get my php form to send


im trying to make an email form and ive been looking after a good way to do this. The problem is that im getting this "Parse error: syntax error, unexpected '<<' (T_SL) on line 12" when i click send. can someone see what the problem is?

<?php

$to = '.........@gmail.com';
$subject='hi there you';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$message = <<<< EMAIL
Hi! My name is $name.
$message
From $name
my email is $email

EMAIL;

$header ='$email';
if($_POST){
mail($to, $subjects, $message, $header);
$feedback = 'Thankyou for your email';
echo $feedback;} ?>

Html

<form action="process.php" method="post">
<ul>
<li>
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" />
</li>
    <li>
    <label for="email">Email:</label>
    <input type="text" name="email" id="email" />
</li>
<li>
<label for="topic">Topic:</label>
<select>
    <option value="optiona">optiona</option>
    <option value="optionb">optionb</option>
    <option value="optionc">optionc</option>
</select>
</li>
<li>
<label for="message">your message:</label>
<textarea id="message" name="message" cols="42" rows="9"></textarea>
</li>
<li><input type="submit" value="Submit"></li>
</form>

Solution

  • You have wrongly used HEREDOCS syntax.

    // Remove one < from below line
    <<<EMAIL
    Hi! My name is $name.
    $message
    From $name
    my email is $email // Remove one line space from below line
    EMAIL;
    

    After <<< operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

    The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

    Note:-

    1) It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon.

    2) It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

    3) If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one.

    4) If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

    5) Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables.

    Hope it will help you :)