gpt4 book ai didi

php - 我不知道为什么这段代码不断出现 t_string 错误

转载 作者:行者123 更新时间:2023-11-29 04:26:18 26 4
gpt4 key购买 nike

我认为我做的一切都是正确的,但我在代码中不断收到 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 = 'username@domain.com';
$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 = 'Support@domain.com';
$mail->AddReplyTo($from_email_address, "Domain.Com");
$mail->SetFrom($from_email_address, "Domain.Com");
$address = "$MessageSentFromMailbox@$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 = "$MessageSentFromMailbox@$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, "name@domain.com","From: name@domain.com");
die();
}

最佳答案

我花了很长时间才弄清楚这个问题,尤其是因为 stackoverflow 似乎已经为您解决了这个问题。在空白 block 中间有许多 0xA0 字符随机散布在您的源代码中(我的编辑器计数为 33)。 PHP 解析器显然不太喜欢这些并抛出错误。

我刚刚在我的编辑器中执行了查找/替换操作,将它们全部转换为空格 (0x20),现在可以解析了。

似乎我第一次编辑你的问题时把它给大家破坏了,因为 SO 纠正了问题,我现在不能通过复制当前显示的代码来重复它,尽管回滚到原始版本- 对不起大家。

如果您将上述代码复制并粘贴回您的编辑器,问题就会消失。 StackOverflow 已积极解决该问题。

关于php - 我不知道为什么这段代码不断出现 t_string 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10608270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com