.haha Posted February 10, 2011 Share Posted February 10, 2011 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","xxx@gmail.com", "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. Quote Link to comment https://forums.phpfreaks.com/topic/227239-issue-with-file_put_contents/ Share on other sites More sharing options...
dreamwest Posted February 10, 2011 Share Posted February 10, 2011 file_put_contents($file, $current, FILE_APPEND | LOCK_EX); Quote Link to comment https://forums.phpfreaks.com/topic/227239-issue-with-file_put_contents/#findComment-1172219 Share on other sites More sharing options...
.haha Posted February 10, 2011 Author Share Posted February 10, 2011 file_put_contents($file, $current, FILE_APPEND | LOCK_EX); Didn't work. But it's alright, I rewrote my code differently and everything's fine now. Quote Link to comment https://forums.phpfreaks.com/topic/227239-issue-with-file_put_contents/#findComment-1172222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.