SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Evil Genius MilchstrabeStern's Avatar
    Join Date
    Nov 2003
    Location
    Arizona
    Posts
    1,131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Want to help me real quick :)

    Hey guys,

    I've been fooling around a lot with imap functions trying to read e-mails and then insert them into a database table.

    I am having a few problems though:

    1) I can't figure out how to count the messages that are returned from the imap_search function. I need this number so I can create a loop later.

    2) I think the body of the e-mail is screwing up the insertion of data into the database. In fact, I'm not even sure why this is in the header, is it something yahoo does that is hidden? How do I make sure that the qoutes from the body or the subject don't interfer with the insertion?

    mySql error

    Data was not added becauseYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Choice 2005 http://mail.yahoo.com', '1' , '9', '0', '86','198The Query was INSERT INTO mos_content (title, title_alias, introtext, state, sectionid, mask, catid, created_by, access) VALUES ('This is a test', 'This is a test', 'This is a body, body body body. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com', '1' , '9', '0', '86','198','1').
    PHP code:

    PHP Code:
    <?php
    $mail_box 
    ="INBOX";
    $email_user "marchingband+mplionhearts.com";
    $email_password "pass";


    $imap imap_open("{mail.mplionhearts.com:143}$mail_box""$email_user""$email_password");
        
        

    $search 'FROM Bryan UNSEEN'//finds all e-mails from Me that have not been read
    $messages imap_search($imap"$search");
    $message_count imap_num_msg($messages); //this is where I need your help!! I can't figure out how to 
                                              //count the results of the search, which is vital for my 
                                              //loop
         
    if($messages==true) { //checks if there is an e-mail that has not been read

         
    foreach ($messages as $message) {
         
         
    $body trim(imap_fetchbody($imap$message,"1"));
         
    $header imap_header($imap$message);
         
    $prettydate date("jS F Y"$header->udate);
         
         echo 
    "$message_count";
          
        
        
    $from $header->fromaddress;
        
    $subject $header->Subject;

        
        echo 
    "$from  - $prettydate\n";
        echo 
    "<br>";
        echo 
    "$subject";
        echo 
    "<br>";
        echo 
    "$body";
        echo 
    "<br>";
        echo 
    "<br>";
        
        
    //a loop will go here eventually (when I get the count working)
        
        
    $db "mplionhe_mplionhearts"
        
    $user "mplionhe"
        
    $password "pass"
        
        
    $link mysql_connect("localhost"$user$password);
        
        if (!
    $link) die ("Can't connect to mysql"); 
         
        
    mysql_select_db($db$link) or die ("cannot connect to $db"); 
        
        
    $query "INSERT INTO mos_content (title, title_alias, introtext, state, sectionid, mask, catid, created_by, access)
        VALUES ('
    $subject', '$subject', '$body', '1' , '9', '0', '86','198','1')"
        
        if (@
    mysql_query ($query)) { print "Data has been added"; } 
        
        else { print 
    "Data was not added because" mysql_error() . "The Query was $query."; } 
         
    mysql_close (); 
         



    } else {


    }
        
    imap_close($imap);
    ?>
    ]

  2. #2
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1)
    PHP Code:
    $messages imap_search($imap"$search");
    //imap_search returns the matching criteria in an array, so all you have to do is count it.
    $number_of_messages count($messages ); 
    2) never used imap so I have no idea....

  3. #3
    Evil Genius MilchstrabeStern's Avatar
    Join Date
    Nov 2003
    Location
    Arizona
    Posts
    1,131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Webnet, that worked.

    Now I surprisingly need help with my loop.

    I know I need to use variables like:

    $body_$i
    $subject_$i

    $i ++

    I'm just not sure how to define these variables with the array that I have ( I believe the information is given in an array). I am also unsure of if I should use a while command or a simple for command.

    Finally, I just need to figure out how to "ignore" or hide quotes from the script that is the result of body content. How do I do that?

    Thanks!
    ]


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •