I'm getting a parse error:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in index.php on line 23
Line 23 is this:
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;
I changed the syntax in all similar lines to
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];
but I get the identical error message.
$er
is an array of email messages. Each array element is an array of key-value pairs, and the value for the key 'header'
is a long array of key-value pairs.
The function $er->GetMessage($i)
returns an array, so this sytax
$er->GetMessage($i)["header"]['fromaddress']
seems like it would work. So, I'm at a loss. The arrow syntax doesn't make sense to me at all, because 'fromaddress'
is not a member of 'header'
— 'header'
is not an object.
What am I missing? I did a search on "Parse error: syntax error, unexpected '[', expecting ',' or ';'" and I found one match. The solution was "- the php wasn't on automatic update so now it is the site is working fine." I don't think this applies to my issue.
The code is below.
Line 23, the line that triggered the error message, is in the for loop.
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;
This is php between body tags:
for ($i=0;$i<$er->GetInboxCount();$i++)
{ // fromaddress, date, subject are from imap_headerinfo
echo br.br;
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];
echo br.br;
echo "<h3>Message received on: </h3>" . $er->GetMessage($i)["header"]['date'];
echo br.br;
echo "<h3>Subject: </h3>" . $er->GetMessage($i)["header"]['subject'];
echo br.br;
echo "<h3>Message in text format:</h3>" . $er->GetMessage($i)['body_text'];
echo br.br;
echo "<h3>Message in html format: </h3>" . $er->GetMessage($i)['body_html'];