mercredi 2 décembre 2015

Retrieving Emails Using Laravel and IMAP,failed to pass varable to view

I have written a code to display emails form gmail:

 public function getMail()
{
    /* connect to gmail */
    $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 variables '$toaddress', '$from' to view it shows only first email id. And i have to add a view button,upon click of that there should come body of that respective email and goes to different method, i passed para $message to that method,

$this->showMail($message);

and method is:

    public function showMail($message){

    return view('emails.showmail',compact('message'));
}

but on click of button there is missing argument error. If anyone knows help me through this!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire