<?php

if (isset($_GET["from"])) {
    $from = $_GET["from"];
}
if (isset($_GET["to"])) {
    $to = $_GET["to"];
}
if (isset($_GET["server"])) {
    $host = $_GET["server"];
}
if (isset($_GET["port"])) {
    $port = $_GET["port"];
}
if (isset($_GET["message"])) {
    $message = $_GET["message"];
}
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
    echo "Unable to connect to SMTP server: {$errstr} ({$errno})\n";
    exit;
}
function get_response($fp)
{
    $response = '';
    while ($str = fgets($fp, 515)) {
        $response .= $str;
        if (substr($str, 3, 1) == ' ') {
            break;
        }
    }
    return $response;
}
function send_command($fp, $command)
{
    fputs($fp, $command . "\r\n");
    echo "CLIENT: {$command}";
    return get_response($fp);
}
echo "SERVER: " . get_response($fp);
$x = explode("@", $from);
$x1 = $x[1];
echo "SERVER: " . send_command($fp, "helo " . gethostname());
echo "SERVER: " . send_command($fp, "MAIL FROM:<{$from}>");
echo "SERVER: " . send_command($fp, "RCPT TO:<{$to}>");
echo "SERVER: " . send_command($fp, "DATA");
$boundary = "----=_Part_" . md5(uniqid());
$email_content = "From: <{$from}>\r\n";
$email_content .= "To: <{$to}>\r\n";
$email_content .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\r\n\r\n";
$email_content .= "--{$boundary}\r\n\r\n\r\n";
$email_content .= "--{$boundary}\r\n";
$email_content .= "Content-Disposition: form-data; name=\"name\"\r\n\r\n";
$email_content .= "{$message} \r\n";
$email_content .= "--{$boundary}--\r\n";
$email_content .= ".\r\n";
echo "CLIENT: {$email_content}\n";
fputs($fp, $email_content);
echo "SERVER: " . get_response($fp);
echo "SERVER: " . send_command($fp, "QUIT");
fclose($fp);