需要帮助使用方法或案例声明更新PHP脚本

This script checks the modified date on a Postfix mailbox folder.

The issue is, I have more than one location that needs to be check.

Folder /mnt/mail1/ contains mail dirs a,b,d,g

Folder /mnt/mail2/ contains the rest c,e,f,h,........,x,z

The script is run simply via the URL https://URL/index.php?email=charlie@delta.com

I need the script to check in the correct mount point depending on the email address being checked. In the case above it should check in /mnt/mail2/d/e/delta.com/.....

Please help. I know 0 to nothing about php.

<?php

if (isset($_REQUEST["email"])) {
    $emailaddress= trim($_REQUEST["email"]);
    $emailparts = explode("@",$emailaddress);
    if (sizeof($emailparts) != 2) {
            print "invalid-email,,,,";
            exit();
    }
    $username = $emailparts[0];
    $domain = $emailparts[1];      
    $basedir = "/mnt/mail1/";
    $livePrefix = $basedir;
    $archivePrefix = $basedir."archive/";
    $livePath = $livePrefix . substr($domain,0,1) . "/" . substr($domain,1,1) . "/" . $domain . "/" . substr($username,0,1) . "/" .  $username;
    $archivePath = $archivePrefix . $domain ;
    $liveStat = stat( $livePath . "/" . "cur");
    $archStat = false;
    if ( file_exists( $archivePath ) && is_dir( $archivePrefix ) ) {
            $arhiveDirs = scandir($archivePath);
            foreach( $arhiveDirs  as $i => $fname ) {
                    if ( stripos( $fname , $username . "-"  ) !== false ) {
                            $archivePath = $archivePath . "/" . $fname ;
                            $archStat = stat( $archivePath . "/cur" );
                            break;
                    }
            }
    }
    $status="lost" ;
    if ( $liveStat != false ) {
            $status = "live" . "," .  date("Y-m-d H:i:s", $liveStat['mtime'] ) . "," . sizeof( scandir($livePath . "/new") ) . "," ;
    } else if ($archStat != false ) {
            $status = "archived,,,";
    } else {
            $status = "lost,,,";
    }

    if ($archStat != false ) {
            $status = $status .  date("Y-m-d H:i:s", $archStat['mtime'] ) . "," . sizeof( scandir($archivePath . "/new") )  ;
    } else {
            $status = $status .  "," ;
    }

    print $status ;
    exit();
} else {
    print "error,,,,";
    exit();
}


?>

Without reading the code and knowing much about php: First, you need to get the email address from the link. Use regex for this. Second, explode the email and get the domain (also with regex).

$domain =

Get the first and the second character of the domain: $domain[0] and $domain[1].

Then you should choose between the two folders two check. Do it with a switch, with 4 main cases: a, b, d, g and a default case that checks the others.

... by the way: shouldn't the case above check the /mnt/mail1/ folder?

the script has everything you need ready:

$domain = $emailparts[1];      
$basedir = "/mnt/mail1/";

you just need to alter the $basedir according to the value in $domain, for example by

switch ($domain[0]) {
    case 'a':
    case 'b':
    case 'd':
    case 'g':
       // fall through: all the cases above reach this point
       $basedir = "/mnt/mail1/";
       break;
    default:
       // all other cases are handled here
       $basedir = "/mnt/mail2/";
 }

but seriously, if you want to maintain such scripts, you should learn the basics. It can be dangerous to just copy/paste code lines from some random strangers on the net. And especially on Stackoverflow, which is a Q and A site, people are usually not willing to just write code