Retrieve emails from gmail and views

Asked

Viewed 24 times

0

I am trying to create my email application. To recover gmail emails to display in my project I am using Mootools Fx.Accordion.

Code:

<html lang="PT-pt">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" content="text/html; charset=utf-8">
        <title>Envio/Recebimento Emails</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
        <script type="text/javascript">
        window.addEvent('domready',function() {
    var togglers = $$('div.toggler');
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$('div.body'));
    togglers.addEvent('click',function() { this.addClass('read').removeClass('unread'); });
    togglers[0].fireEvent('click'); //first one starts out read
        }); 
        </script>
</head>
<body>
<?php   
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username1 = '[email protected]';
$password1 = 'xxxxxxxxx';

/* try to connect */
$inbox = imap_open($hostname,$username1,$password1) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email... */
    foreach($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,0);
        $message = imap_fetchbody($inbox,$email_number,2);

        /* output the email header information */
        $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
        $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
        $output.= '<span class="from">'.$overview[0]->from.'</span>';
        $output.= '<span class="date">on '.$overview[0]->date.'</span>';
        $output.= '</div>';

        /* output the email body */
        $output.= '<div class="body">'.$message.'</div>';
    }

    echo $output;
} 

/* close the connection */
imap_close($inbox); 
?> 

But I get the following error with the function window.addEvent:

Uncaught Typeerror: window.addEvent is not a Function

  • 1

    Would not be addEventListener? See the element.addeventlistener documentation() to confirm.

  • @Lipespry yes, I checked the documentation and it is addEventListener. But I run the code and it’s not displaying any email messages

  • One thing at a time. Solved the question problem?

  • @Lipespry yes solved

  • 1

    I read an article about this Mootools and has a function of it named addEvent. Leave this question open, because someone who knows the tool can confirm this thesis and formulate a more appropriate answer.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.