Search code examples
phpimap

PHP IMAP authenticate my credentials and give me good and bad login in txt


I have a PHP IMAP code I wrote that makes me manually type in my email and password to validate/authenticate. If I input a wrong password it gives me "not connect" and if I type in my right password it displays "CONNECT".

<?php
$email = $_REQUEST['email'];
$domcom = trim(strstr($email, '@'), '@');
$mbox = imap_open("{mail.$domcom:993/imap/ssl/novalidate-cert/notls}", "[email protected]", "password");
if ($mbox == true)
{
   echo "CONNECT";
}
else
{
   echo "NOT CONNECT";
}
?>

So what I need is I don't want to manually type it myself again. I need help with fixing the script for it to do the work automatically, that I have my email:password like this in a log.txt file in the format below:

[email protected]:password1 
[email protected]:password2
[email protected]:password3
[email protected]:password4
[email protected]:password5
[email protected]:password6
[email protected]:password7 
[email protected]:password8
[email protected]:password9
[email protected]:password10 
[email protected]:password11
[email protected]:password12

So, if I run the imap.php script on browser it checks them automatically line by line till it finishes, and gives me "good.txt" for authenticated login that connects and "bad.txt" for bad login.

Note: I want the IMAP server in quote "" to remain the same.

{mail.$domcom:993/imap/ssl/novalidate-cert/notls}

Make $domcom call the domain part in each line of the txt and post it on the IMAP server line of code.


Solution

  • Kindly put below code in your imap.php

    <?php
    
    $lines = file('log.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    
    foreach($lines as $line){
        list($email, $password) = explode(':', $line);
    
        $domcom = trim(strstr($email, '@'), '@');
        $mbox   = imap_open("mail.{$domcom}:993/imap/ssl/novalidate-cert/notls", $email, $password);
        if( $mbox == true ){
            file_put_contents('good.txt', $line."\n", FILE_APPEND);
        }else{
            file_put_contents('bad.txt', $line."\n", FILE_APPEND);
        }
    }
        
    ?>
    

    And below in the log.txt

    [email protected]:password1
    [email protected]:password2
    [email protected]:password3
    [email protected]:password4
    [email protected]:password5
    [email protected]:password6
    [email protected]:password7
    [email protected]:password8
    [email protected]:password9
    [email protected]:password10
    [email protected]:password11
    [email protected]:password12
    

    Source

    file() - https://www.php.net/manual/en/function.file.php

    file_put_contents() - https://www.php.net/manual/en/function.file-put-contents.php