Jump to content

Checking email exists in .txt file


graham23s

Recommended Posts

Hi Guys,

 

I'm using the following code to write emails to a .txt file:

 


                // Write the email to file
                $leadsFile = "leads/emails.txt";
                $fh = fopen($leadsFile, 'a') or die ("can't open leads file!");
                $writeData = "$conEM\r\n";
                fwrite($fh, $writeData);
                fclose($fh); 

 

which works great, but i can't figure out how to NOT write an email to the .txt file if it's already on it, i'm not using a database for a change i'm stumped lol

 

thanks for any help guys

 

Graham

 

 

Link to comment
https://forums.phpfreaks.com/topic/210724-checking-email-exists-in-txt-file/
Share on other sites

I'd first read the text file using file. Next use in_array to see if the email already exists. For example

$leadsFile = "leads/emails.txt";

$emails = file($leadsFile, FILE_IGNORE_NEW_LINES);
if(!in_array($conEM, $emails))
{
     // write email to text file
     $fh = fopen($leadsFile, 'a') or die ("can't open leads file!");
     $writeData = "$conEM\r\n";
     fwrite($fh, $writeData);
     fclose($fh); 
}

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.