2011-03-24 140 views
8

我對PHP相當陌生,我使用的腳本創建了一個名爲「mime_mailer」的函數,它基本上允許我使用PHP發送可以用CSS設計的電子郵件僅僅是純文本。語法錯誤,意外T_SL

但是,在我的註冊腳本中,我嘗試編寫一些發送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 <[email protected]>\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); 
} 

這裏是「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; 
} 
?> 
+1

發佈指示行號和在張貼代碼 – 2011-03-24 08:22:16

+0

的錯誤是在註冊腳本定義行數的錯誤消息。它在第六行。 $ message變量被定義的行。在<<< END是... – Lance 2011-03-24 08:23:51

回答

11

看看List of Parser tokens

T_SL<<的引用。

在使用END;之前,不應使用製表符或空格。看看this huge warning

+0

我將<<< END切換到<< END並在END END之前刪除了製表符和空格,並且仍然顯示相同的錯誤消息。 – Lance 2011-03-24 08:33:47

+0

@Lance:您應該將<< << END'改回到<< << END'。您應該只刪除與END;'在同一行上的製表符和空格。 – 2011-03-24 08:35:10

0

有在function_mime_mailer.php了一個錯誤:

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

應該

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

還,如果包括的MIME版本頭,則該函數將包括這一次 - 有效有兩個。

18

剛剛有同樣的問題。

竟然是在同一條線上內容,我開HERDEOC

錯誤的榜樣

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

正確的示例

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

希望這可以幫助其他人!

+0

它幫助我!謝謝:) – 2013-06-03 18:44:09

+0

值得指出的是,即使是空格字符(可能會隱藏在您的編輯器中)也會導致此問題。這是一個腦th until直到你找到它。 – JakeParis 2017-10-27 20:58:01

1

一個方面的說明,但可能很好的幫助某人:一個糟糕的git合併可以導致這種情況。考慮:

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

PHP解析器會產生相同的錯誤。

源:本剛剛位)