Banana Code
Banana Code

Reputation: 817

"Server Error" displayed on the browser when using the PHP function of imap_header

Summary

I try to read the information of the first letter in my mailbox. Suppose that "mail.example.com" is my mail server site, "userid" is my e-mail address and "userpwd" is my password. Below is the PHP code.

<?php
$num=1;         //To read the first letter

$MAILSERVER="{mail.example.com:143/notls}INBOX";
$link=imap_open($MAILSERVER,"userid","userpwd");
$header=imap_header($link,$num);

echo "From: $header[fromaddress]<br>";
echo "To: $header[toaddress]<br>";
echo "Date: $header[Date]<br>";
echo "Subject: $header[Subject]<br><br>";
echo imap_body($link,$num);

imap_close($link);
?>

Questions

I have two questions:

  1. According to the PHP code above, why the output result is "Server Error"?
  2. Why $link has no return value when we do not add "/notls" on line 4?

Upvotes: 1

Views: 292

Answers (1)

dharanbro
dharanbro

Reputation: 1342

try this. you are using invalid array index

$MAILSERVER="{mail.example.com:143/notls}INBOX";
$link=imap_open($MAILSERVER,"userid","userpwd");
$header=imap_header($link,$num);

echo "From:". $header['fromaddress']."<br>";
echo "To:". $header['toaddress']."<br>";
echo "Date:".$header['Date']."<br>";
echo "Subject:". $header['Subject']."<br><br>";
echo imap_body($link,$num);

imap_close($link);
?>

Upvotes: 2

Related Questions