语法错误,意外的T_SL

Lan*_*nce 9 php mime

我对php很新,我正在使用一个创建一个名为"mime_mailer"的函数的脚本,它实际上允许我使用PHP发送能够用CSS设计而不仅仅是纯文本的电子邮件.

然而,在我的注册脚本中,我尝试编写一些发送CSS电子邮件的代码,但是我收到一条错误消息,指出存在语法错误.有人可以请我填一下吗?

            $subject = "Your Red-line Account";
    $css     = "body{ color: #090127; background-color: #f0f0f0; }"; 
    $to     =   $usercheck;

    //Message
    $message =<<<END 
                <html>
                    <head>
                        <title>
                            Red-line
                        </title>
                    </head>
                    <body>
                        <p>
                            Hi $first_name, 
                        </p> 

                        <p>
                            Your Red-line account is almost complete. To finish, go to <a href='www.thered-line.com'>The Red-line</a> and enter your eight digit confirmation code.
                        </p> 

                        <p>
                            Your confirmation code is: <b>$code</b>
                        </p> 

                        <p>
                            Sincerely,
                        </p> <br />

                        <p>
                            The Red-line Operator
                        </p> 
                    </body>
                </html>
            END;

                    //  To send HTML mail, the Content-type header must be set
        $headers    =   'MIME-Version: 1.0' . "\r\n";
        $headers    .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                    //  Additional headers
        $headers    .=  "From: The Red-line <messages@theredline.com>\r\n";
        $headers    .=  "To: $first_name $last_name <$usercheck>\r\n";

                    //  Mail it
        require_once("function_mime_mailer.php");


        mime_mailer($to, $subject, $message, $headers, NULL, $css); 
}
Run Code Online (Sandbox Code Playgroud)

这是"function_mime_mailer.php"文件的代码.

  if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])) send_404(); // stop http access           to         this file

 function mime_mailer($to, $subject, $message, $headers = NULL, $attachments = NULL, $css = NULL)
 {
       if(!preg_match('/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-        z]{2,6})$/', $to)) return FALSE;
if(preg_match('/<(html|head|body|div|a|h|p|table|br|img|b|hr|ol|ul|span|pre|i|form)[^>]*[^>]*>/i', $message)) $html = TRUE;

 if(stristr($message, '<body')) $message = stristr($message, '<body');
     $message = delete_local_links($message);
 if(empty($headers)){
     $headers = "MIME-Version: 1.0\n";
 }else{
     $headers.= "\nMIME-Version: 1.0\n";
 }
 if(empty($html)){
     $result = plain_text($message);
 }elseif(isset($html) and $html == TRUE){
     if(!isset($css)) $css = NULL;
     if(preg_match('/<img[^>]+>/i', $message)){
       $result = multipart_related($message, $css);
   }else{
       $result = multipart_alternative($message, $css);
   }
 }
 $result['message'] = delete_non_cid_images($result['message']);
 if(!empty($attachments)){
   $parts = attachments($attachments);
   array_unshift($parts, implode('', $result));
   $result = multipart_mixed($parts);
 }
$headers = $headers.$result['headers'];
//print '<pre>'.htmlspecialchars($headers.$result['message']).'</pre>';exit;
if(mail($to, $subject, $result['message'], $headers)) return TRUE;
return FALSE;
}
?> 
Run Code Online (Sandbox Code Playgroud)

pen*_*ner 21

刚遇到同样的问题.

结果与我开设的HERDEOC在同一条线上有所满足

错误的例子

echo <<<HEREDOC code started on this line
HEREDOC;
Run Code Online (Sandbox Code Playgroud)

正确的例子

echo <<<HEREDOC
code should have started on this line
HEREDOC;
Run Code Online (Sandbox Code Playgroud)

希望这有助于其他人!

  • 值得指出的是,即使是空格字符(可能隐藏在您的编辑器中)也会导致此问题。_那是_一个脑筋急转弯,直到你找到它。 (3认同)

Mic*_*ter 12

看一下Parser令牌列表.

T_SL参考<<.

使用前不应使用制表符或空格END;.看看这个巨大的警告.


Kev*_*sey 6

附注,但可能会对某人有所帮助:错误的 git 合并可能会导致这种情况。考虑:

function foo
    <<<<<<< HEAD
    $bar = 1;
    <<<<<<<  e0f2213bc34d43ef
    $bar = 2;
Run Code Online (Sandbox Code Playgroud)

PHP 解析器会产生相同的错误。

来源:刚刚被这个咬了;)


小智 5

它有完全相同的问题,但我的问题是因为我在顶行的定界符末尾有空格:

$var = <<< HTML(whitespaces here caused the error)
stuff in here
Run Code Online (Sandbox Code Playgroud)

HTML;

来源:http ://realtechtalk.com/_syntax_error_unexpected_T_SL_in_PHP_Solution-2109-articles