Syntax error, unexpected T_SL

2020-07-06 06:19发布

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 designed with CSS instead of being merely plain text.

Yet, in my registration script, I try to write some code that sends a CSS email, but I get an error saying that there's a syntax error. Could someone please fill me in on this?

            $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); 
}

Here is the code for the "function_mime_mailer.php" file.

  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;
}
?> 

标签: mime php
6条回答
女痞
2楼-- · 2020-07-06 06:28

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.

查看更多
smile是对你的礼貌
3楼-- · 2020-07-06 06:38

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

查看更多
Evening l夕情丶
4楼-- · 2020-07-06 06:41

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 ;)

查看更多
别忘想泡老子
5楼-- · 2020-07-06 06:43

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!

查看更多
一夜七次
6楼-- · 2020-07-06 06:48

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

查看更多
成全新的幸福
7楼-- · 2020-07-06 06:48

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.

查看更多
登录 后发表回答