Jump to content

Issue with file_put_contents


.haha

Recommended Posts

I'm attempting to have a script that when complete, will access my email account, add all the email addresses of senders to a database (just a text file for now), and mail the list out once a week. At the moment, however, I am stuck.

 

I'm using put_file_contents to try and add these addresses to a text file, but it only writes one email address. My code is as follows.

 

<?php
    $imap = imap_open("{imap.gmail.com:993/imap/ssl}INBOX","[email protected]", "xxx" );
    $message_count = imap_num_msg($imap);

    for ($i = 1; $i <= $message_count; ++$i) {
        $header = imap_header($imap, $i);

        if (isset($header->from[0]->personal)) {
            $personal = $header->from[0]->personal;
        } else {
            $personal = $header->from[0]->mailbox;
        }

        $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";


$fromaddr = $header->from[0]->mailbox . "@" . $header->from[0]->host;



  echo "$fromaddr <br>";



    }

$file = 'database.txt';
$current = file_get_contents($file);
$current .= ($header->from[0]->mailbox . "@" . $header->from[0]->host);
file_put_contents($file, $current);



    imap_close($imap);



?>

 

The echo shows all the email addresses when I load the page, but when I try to write it, it only writes the last one displayed. How do I resolve this issue?

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/227239-issue-with-file_put_contents/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.