2012-05-15 134 views
1

我想我正在做的一切正確,但我不斷收到代碼中的t_string錯誤。我會顯示什麼線路。如果任何人都能弄清楚這一點,我會非常感激。我確實對引號進行了研究,並且正在考慮可能數據庫中的數據與錯誤有關,因爲它包含@符號和句點。我不知道爲什麼這段代碼不斷收到t_string錯誤

的錯誤是在76線是if(empty($row['email']))

整個代碼

ini_set("include_path", ".:/public_html/phpmailer"); //Used for simplicity 
include("mysql_connect.php"); //The database name, login, etc.. 
set_error_handler("customError"); //I created a custom error 

$login = '[email protected]'; 
$password = 'password'; 
$server = '{imap.gmail.com:993/ssl/novalidate-cert}'; 
$connection = imap_open($server, $login, $password); 

$mailboxinfo = imap_mailboxmsginfo($connection); 
$messageCount = $mailboxinfo->Nmsgs; //Number of emails in the inbox 
for ($MID = 1; $MID <= $messageCount; $MID++) 
    { 
    $EmailHeaders = imap_headerinfo($connection, $MID); //Save all of the header information 
    $Body = imap_qprint(imap_fetchbody($connection, $MID, 1)); //The body of the email to be forwarded 
    $MessageSentToAllArray = $EmailHeaders->to; //Grab the 「TO」 header 
    $MessageSentToAllObject = $MessageSentToAllArray[0]; 
    $MessageSentToMailbox = $MessageSentToAllObject->mailbox; //Everything before the 「@」 of the recipient 
    $MessageSentToHost = $MessageSentToAllObject->host; //Everything after the 「@」 of the recipient 
    $MessageSentFromAllArray = $EmailHeaders->from; //Grab the 「FROM」 header 
    $MessageSentFromAllObject = $MessageSentFromAllArray[0]; 
    $MessageSentFromMailbox = $MessageSentFromAllObject->mailbox; //Everything before the 「@」 of the sender 
    $MessageSentFromHost = $MessageSentFromAllObject->host; //Everything after the 「@」 of the sender 
    $MessageSentFromName = $MessageSentFromAllObject->personal; //The name of the person who sent the email 
    $toArray = searchRecipient($MessageSentToMailbox); //Find the correct person to send the email to 
    if($toArray == FALSE) //If the alias they entered doesn’t exist… 
    { 
    $bounceback = 'Sorry the email in your message does not appear to be correct'; 
    /* Send a bounceback email */ 
    $mail = new PHPMailer(); // defaults to using php 「mail()」 
    $mail -> ContentType = ‘text/plain’; //Plain email 
    $mail -> IsHTML(false); //No HTML 
    $the_body = wordWrap($bounceback, 70); //Word wrap to 70 characters for formatting 
    $from_email_address = '[email protected]'; 
    $mail->AddReplyTo($from_email_address, "Domain.Com"); 
    $mail->SetFrom($from_email_address, "Domain.Com"); 
    $address = "[email protected]$MessageSentFromHost"; //Who we’re sending the email to 
    $mail->AddAddress($address, $MessageSentFromName); 
    $mail->Subject = 'WAHM Link Request'; //Subject of the email 
    $mail->Body = $the_body; 
    if(!$mail->Send()) //If the mail fails, send to customError 
     { 
     customError(1, $mail->ErrorInfo, "anon-email.php", "sending the email"); 
     } 
    } 
    else //If the candidate address exists, forward on the email 
    { 
    $mail = new PHPMailer(); // defaults to using php 「mail()」 
    $mail -> ContentType = ‘text/plain’; //Plain E-mail 
    $mail -> IsHTML(FALSE); //No HTML 
    $the_body = wordwrap($Body, 70); //Wordwrap for proper email formatting 
    $from_email_address = "[email protected]$MessageSentFromHost"; 
    $mail->AddReplyTo($from_email_address, $MessageSentFromName); 
    $mail->SetFrom($from_email_address, $MessageSentFromName); 
    $address = $toArray[1]; //Who we’re sending the email to 
    $mail->AddAddress($address, $toArray[0]); //The name of the person we’re sending to 
    $mail->Subject = $EmailHeaders->subject; //Subject of the email 
    $mail->Body = ($the_body); 
    if(!$mail->Send()) //If mail fails, go to the custom error 
     { 
     customError(1, $mail->ErrorInfo, "anon-email.php", "sending the email"); 
     } 
    } 
    /* Mark the email for deletion after processing */ 
    imap_delete($connection, $MID); 
    } 
    imap_expunge($connection); // Expunge processes all of the emails marked to be deleted 
    imap_close($connection); 

    function searchRecipient() // function to search the database for the real email 
{ 
    global $MessageSentToMailbox; // bring in the alias email 
    $email_addr = mysql_query("SELECT email FROM tbl WHERE source='$MessageSentToMailbox'"); // temp store of the real email 
    $row = mysql_fetch_assoc($email_addr); //making temp store of data for use in program 
   if(empty($row['email'])) 
   { 
       return FALSE; 
   } 
   else  /* Else, return find the person's name and return both in an array */ 
   { 
       $query = "SELECT * FROM tbl WHERE email = '$email_addr'"; // pulling in the row where the emails match 
       $results = mysql_query($query, $email_addr); // temp store of both queries from this function 
     $row = mysql_fetch_assoc($results); //making temp store of data for use in program 
       $name = $row['author']; // taking the author data and naming its variable 
       return array($name, $email_addr); // this is the name and the real email address to be used in function call 
   } 
} 

function customError($errno, $errstr, $file, $line) 
{ 
    error_log("Error: [$errno] $errstr in $file at line number: $line",1, "[email protected]","From: [email protected]"); 
    die(); 
} 
+0

我在這段代碼中沒有運行'php -l'的語法錯誤。 –

+0

@Michael你添加了一個'<?php'嗎?我實際上得到了同樣的錯誤分析與5.3.8 – DaveRandom

+0

@DaveRandom是的,5.3.10和沒有錯誤。 –

回答

2

我不知道這是錯誤的,但你在這裏有看中的單引號:

$mail -> ContentType = ‘text/plain’; //Plain email

它實際上在您的代碼中出現兩次。

3

我花了很長時間才弄清楚這一點,不僅僅是因爲看起來stackoverflow已經爲你解決了這個問題。在你的源代碼中有幾個隨機散佈的字符(我的編輯器數量爲33)位於空白區塊的中間。 PHP解析器顯然不太喜歡這些,並拋出一個錯誤。

我剛剛在我的編輯器中查找/替換,將它們全部轉換爲空格(0x20),現在它解析。

看來,我第一次編輯你的問題讓我感到受寵若驚,因爲SO糾正了問題,我現在無法通過複製當前顯示的代碼來重複它,儘管回滾到原始狀態版本 - 抱歉大家。

如果您將上面的代碼複製並粘貼回您的編輯器,問題就消失了。 StackOverflow已經積極解決了這個問題。

+0

+1對於SO獲得智力和自我意識,開始自行修正代碼。 –

+0

現在,只要我們能教它將'mysql_real_escape_string()'調用插入n00b PHP代碼或重構爲PDO ... –

+0

@Michael大聲笑,或指出缺少花括號。如果你感興趣,[這裏](http://pastebin.com/bwYUbAq9)是原始損壞數據的粘貼 - pastebin似乎在不改變它的情況下玩遊戲 – DaveRandom

相關問題