DGinformatisering

PHP scripts

Array to string

Ever needed to print an Array dump into an e-mail for debugging reasons? You probably have.
This script makes an organised dump for your text-only e-mail.

/**********************************************************
************ (c) 2012 DG Informatisering    *************
***********************************************************/

function arrayToString($arr, $indent = " ", $string = "") {
    foreach($arr as $key => $value){
        if(is_array($value)) {
            $string .= "{$indent}[{$key}] \r";
            arrayToString($value, $indent."  ", &$string);
        }
        else $string .= "{$indent}[{$key}] => {$value}\r";
    }
    return $string;
}

 

Check if mailserver exists

/**********************************************************
************ (c) 2012 DG Informatisering    *************
***********************************************************/

$email = "info@dginfo.nl";
$domainexp = explode("@", $email);
$domain = $domainexp[1];
$dns = dns_get_record($domain);

$MX = Array();
foreach($dns as $record){
    if($record["type"]=="MX") $MX[]=$record["target"];
}

foreach($MX as $server){
    $sock = fsockopen($server, 25, $errno, $errstr, 1);
    stream_set_timeout($sock, 1);
    if($sock) break;
}

if($sock) {
    fclose($sock);
    echo "connect successful";
}
else echo "connect failed";