Пример #1
0
function sendtestmail($from, $to)
{
    $unix = new unix();
    $smtp = new smtp();
    $tt = explode("@", $to);
    $domainname = $tt[1];
    $TargetHostname = $smtp->ResolveMXDomain($tt[1]);
    echo "Connect: {$TargetHostname}\n ";
    $params["host"] = $TargetHostname;
    $params["helo"] = $unix->hostname_g();
    if (!$smtp->connect($params)) {
        smtp::events("[{$domainname}] {$domainname} -> Could not connect to  `{$TargetHostname}`", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $body[] = "Return-Path: <{$from}>";
    $body[] = "X-Original-To: {$to}";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$from} (Test sender)";
    $body[] = "Subject: Test mail " . date("D, d M Y H:i:s");
    $body[] = "To: {$to}";
    $body[] = "Auto-Submitted: auto-replied";
    $body[] = "MIME-Version: 1.0";
    $body[] = "";
    $body[] = "This is a tests mail";
    $MAILDATA = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => $from, "recipients" => $to, "body" => $MAILDATA))) {
        echo "Failed\n";
        return;
    }
    $smtp->quit();
    echo "Success from=<{$from}> to=<{$to}>\n";
}
Пример #2
0
function SendTest($Key)
{
    $GLOBALS["WRITETOFILE"] = dirname(__FILE__) . "/ressources/logs/{$Key}.log";
    $sock = new sockets();
    $unix = new unix();
    $datas = unserialize(base64_decode($sock->GET_INFO($Key)));
    $listen_addr = null;
    $recipient = $datas["smtp_dest"];
    $sender = $datas["smtp_sender"];
    smtp::events("Resolving From {$sender} to: {$recipient}", __FUNCTION__, __FILE__, __LINE__);
    if (preg_match("#(.+?)@(.+)#", $recipient, $re)) {
        $domainname = $re[2];
    }
    if (!is_numeric($datas["smtp_auth"])) {
        $datas["smtp_auth"] = 0;
    }
    $TargetHostname = null;
    $servername = $datas["servername"];
    $BinDTO = "127.0.0.1";
    if ($servername != "master") {
        $instance = $servername;
        $main = new maincf_multi($servername);
        $listen_addr = $main->ip_addr;
        $BinDTO = $listen_addr;
    } else {
        $instance = $unix->hostname_g();
    }
    $smtp = new smtp();
    $NOresolvMX = false;
    if ($datas["smtp_auth"] == 1) {
        $TargetHostname = $datas["relay"];
    }
    if ($datas["smtp_local"] == 1) {
        $TargetHostname = inet_interfaces();
        if (preg_match("#all#is", $TargetHostname)) {
            $TargetHostname = "127.0.0.1";
        }
        smtp::events("Local, instance {$servername}: Sock to `{$TargetHostname}`", __FUNCTION__, __FILE__, __LINE__);
        if ($servername != "master") {
            smtp::events("Local, instance {$servername}: changed to inet_interfaces()::{$TargetHostname}", __FUNCTION__, __FILE__, __LINE__);
            $TargetHostname = $listen_addr;
        }
    }
    if ($TargetHostname == null) {
        $TargetHostname = $smtp->ResolveMXDomain($domainname);
        smtp::events("Resolving {$domainname} = `{$TargetHostname}` bind address: {$BinDTO}", __FUNCTION__, __FILE__, __LINE__);
    }
    $params["helo"] = $instance;
    $params["bindto"] = $BinDTO;
    $params["debug"] = true;
    smtp::events("smtp_auth: {$datas["smtp_auth"]}, user:{$params["user"]},relay:{$datas["relay"]} ", __FUNCTION__, __FILE__, __LINE__);
    smtp::events("Me: HELO: {$instance}", __FUNCTION__, __FILE__, __LINE__);
    if ($datas["smtp_auth"] == 1) {
        $params["auth"] = true;
        $params["user"] = $datas["smtp_auth_user"];
        $params["pass"] = $datas["smtp_auth_passwd"];
        if (trim($datas["relay"]) == null) {
            if ($TargetHostname != null) {
                $datas["relay"] = $TargetHostname;
            }
        }
        $TargetHostname = $datas["relay"];
    }
    $params["host"] = $TargetHostname;
    if (!$smtp->connect($params)) {
        smtp::events("Error {$smtp->error_number}: Could not connect to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $boundary = md5(uniqid(microtime(), TRUE));
    $body[] = "Return-Path: <{$sender}>";
    $body[] = "X-Original-To: {$recipient}";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$sender} (Mail Delivery System)";
    $body[] = "Subject: Test Message";
    $body[] = "To: {$recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = "This is the mail system at host {$instance}.";
    $body[] = "";
    $body[] = "I'm glade to inform you that your message is";
    $body[] = " delivered to you...";
    $body[] = "";
    $body[] = "For further assistance, please send mail to postmaster.";
    $body[] = "";
    $body[] = "If you do so, please include this problem report. You can";
    $body[] = "delete your own text from the attached returned message.";
    $body[] = "";
    $body[] = "                   The mail system";
    $body[] = "";
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => $sender, "recipients" => $recipient, "body" => $finalbody, "headers" => null))) {
        smtp::events("Error {$smtp->error_number}: Could not send to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        $smtp->quit();
        return;
    }
    smtp::events("Success sending message trough [{$TargetHostname}:25]", __FUNCTION__, __FILE__, __LINE__);
    $smtp->quit();
    smtp::events("Test message Success From=<{$sender}> to=<{$recipient}> ", __FUNCTION__, __FILE__, __LINE__);
    chmod($GLOBALS["WRITETOFILE"], 0775);
}