Syntax error, unexpected T_SL

后端 未结 6 2752
北海茫月
北海茫月 2021-02-20 08:34

I\'m fairly new to php and I\'m using a script that creates a function called the \"mime_mailer\" which essentially allows me to use PHP to send emails that are able to be desig

相关标签:
6条回答
  • 2021-02-20 09:01

    What version of php are you using? The nowdoc syntax is only valid since PHP 5.3.0. See the manual: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc

    0 讨论(0)
  • 2021-02-20 09:06

    Just had the same problem.

    Turned out to be content on the same line as my opening HERDEOC

    wrong example

    echo <<<HEREDOC code started on this line
    HEREDOC;
    

    correct example

    echo <<<HEREDOC
    code should have started on this line
    HEREDOC;
    

    Hope this helps someone else!

    0 讨论(0)
  • 2021-02-20 09:08

    There is a bug in function_mime_mailer.php:

    if(empty($headers)){
       $headers = "MIME-Version: 1.0\n";
    }else{
       $headers.= "\nMIME-Version: 1.0\n";
    }
    

    should be

    if(empty($headers)){
       $headers = "MIME-Version: 1.0\r\n";
    }else{
       $headers.= "\r\nMIME-Version: 1.0\r\n";
    }
    

    also, if you include the MIME-Version header, then the function will include it once more - effectively having two of them.

    0 讨论(0)
  • 2021-02-20 09:14

    Have a look at the List of Parser tokens.

    T_SL references to <<.

    You should not use tabs or spaces before you use END;. Have a look at this huge warning.

    0 讨论(0)
  • 2021-02-20 09:20

    A side note, but might well help someone: a bad git merge can cause this. Consider:

    function foo
        <<<<<<< HEAD
        $bar = 1;
        <<<<<<<  e0f2213bc34d43ef
        $bar = 2;
    

    The PHP parser would produce the same error.

    Source: just got bit by this ;)

    0 讨论(0)
  • 2021-02-20 09:24

    It had the same exact same issue but mine was because I had whitespace at the end of my heredoc on the top line:

    $var = <<< HTML(whitespaces here caused the error)
    stuff in here
    

    HTML;

    Source: http://realtechtalk.com/_syntax_error_unexpected_T_SL_in_PHP_Solution-2109-articles

    0 讨论(0)
提交回复
热议问题