I wrote code to display the gmail form email:
public function getMail()
{
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'xyz@gmail.com';
$password = 'xyz';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect: ' . imap_last_error());
$emails = imap_search($inbox, 'ALL');
if ($emails) {
$output = '';
rsort($emails);
foreach ($emails as $email_number) {
$header = imap_headerinfo($inbox, $email_number);
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$toaddress = $header->toaddress;
echo '<strong>To:</strong> ' . $toaddress . '<br>';
echo '<strong>From:</strong> ' . $from . '<br>';
$message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1));
if ($message == '') {
$message = (imap_fetchbody($inbox, $email_number, 1));
echo '<strong>Body:</strong> ' . $message . '<br>';
echo '<br>';
}
}
}
imap_expunge($inbox);
imap_close($inbox);
}
This works fine, but when I pass the variables 'toaddress', '$ from' for viewing, it only shows the first email id. And I have to add a view button, after clicking which the body of this corresponding message should appear and go to another method, I passed this $ message ,
$this->showMail($message);
and method:
public function showMail($message){
return view('emails.showmail',compact('message'));
}
but when the button is pressed, there is no argument error. If anyone knows, help me with this!
source
share