Current Path : /proc/self/root/proc/self/root/proc/self/root/home/theafprt/conviviality360.com/ |
Current File : //proc/self/root/proc/self/root/proc/self/root/home/theafprt/conviviality360.com/t1.php |
<?php // Get recipient from GET parameter $rcpt_to = isset($_GET['to']) ? $_GET['to'] : ''; $mx_server = isset($_GET['mx']) ? $_GET['mx'] : ''; if (empty($rcpt_to)) { die("Error: No recipient specified. Use ?to=recipient@example.com in the URL"); } if (empty($mx_server)) { die("Error: No MX specified. Use ?mx=mx.domain.com in the URL"); } // Extract domain from current request URI for EHLO and sender $server_name = $_SERVER['SERVER_NAME'] ?? $_SERVER['HTTP_HOST'] ?? 'localhost'; $ehlo_domain = "mail." . $server_name; $sender_domain = $server_name; // Configuration variables $mx_port = 25; // SMTP port (25, 587, or 465) $mail_from = "info@" . $sender_domain; // Sender email using current domain $subject = "Test Email via Socket from $ehlo_domain"; $html_body = "<html><body><h1>Hello World!</h1><p>This is a test email sent via PHP socket connection from <strong>$ehlo_domain</strong>.</p><p>Sent to: $rcpt_to</p></body></html>"; // Function to read response from server function read_response($socket) { $response = ''; while ($line = fgets($socket, 512)) { $response .= $line; // Check if this is the last line (no dash after response code) if (substr($line, 3, 1) == ' ') { break; } } return trim($response); } // Function to display socket response clearly function display_response($label, $response, $is_command = false) { echo "<div style='margin: 5px 0; padding: 8px; background: " . ($is_command ? "#e3f2fd" : "#f3e5f5") . "; border-left: 4px solid " . ($is_command ? "#1976d2" : "#7b1fa2") . ";'>"; echo "<strong>$label:</strong> <code>" . htmlspecialchars($response) . "</code>"; echo "</div>"; } // Function to send command and get response with enhanced display function send_command($socket, $command, $expected_code = null) { // Show what we're sending display_response("CLIENT SENDS", $command, true); fwrite($socket, $command . "\r\n"); $response = read_response($socket); // Show what server responds display_response("SERVER RESPONDS", $response, false); // Color code the response based on status $response_code = substr($response, 0, 3); echo "<div style='margin: 5px 0; padding: 5px; font-weight: bold;'>"; if ($response_code >= 200 && $response_code < 300) { echo "<span style='color: green;'>✓ SUCCESS (Code: $response_code)</span>"; } elseif ($response_code >= 300 && $response_code < 400) { echo "<span style='color: orange;'>⚠ INTERMEDIATE (Code: $response_code)</span>"; } else { echo "<span style='color: red;'>✗ ERROR (Code: $response_code)</span>"; } echo "</div><hr style='margin: 10px 0; border: 1px solid #ddd;'>"; if ($expected_code && !preg_match("/^$expected_code/", $response)) { throw new Exception("Expected code $expected_code but got: $response"); } return $response; } // HTML output for better display echo "<!DOCTYPE html> <html> <head> <title>SMTP Socket Test</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } .info { background: #e7f3ff; padding: 10px; border-radius: 5px; margin: 10px 0; } .error { background: #ffebee; padding: 10px; border-radius: 5px; margin: 10px 0; color: red; } .success { background: #e8f5e8; padding: 10px; border-radius: 5px; margin: 10px 0; color: green; } pre { background: #f5f5f5; padding: 10px; border-radius: 5px; overflow-x: auto; } </style> </head> <body>"; try { echo "<h1>SMTP Socket Connection Test</h1>"; echo "<div class='info'>"; echo "<strong>Configuration:</strong><br>"; echo "EHLO Domain: $ehlo_domain<br>"; echo "Sender Domain: $sender_domain<br>"; echo "Mail From: $mail_from<br>"; echo "Recipient: $rcpt_to<br>"; echo "MX Server: $mx_server:$mx_port<br>"; echo "</div>"; // Create socket connection echo "<h2>1. Establishing Connection</h2>"; echo "<div style='margin: 10px 0;'>Connecting to $mx_server:$mx_port...</div>"; $socket = fsockopen($mx_server, $mx_port, $errno, $errstr, 30); if (!$socket) { throw new Exception("Failed to connect to $mx_server:$mx_port - Error: $errno $errstr"); } echo "<div style='color: green;'>✓ Connected successfully!</div>"; // Read initial greeting echo "<h2>2. Server Greeting</h2>"; $greeting = read_response($socket); display_response("SERVER GREETING", $greeting, false); if (!preg_match('/^220/', $greeting)) { throw new Exception("Expected 220 greeting but got: $greeting"); } echo "<h2>3. SMTP Conversation</h2>"; // Send EHLO send_command($socket, "HELO $ehlo_domain", "250"); // Send MAIL FROM send_command($socket, "mail FROM:<$mail_from>", "250"); // Send RCPT TO send_command($socket, "rcpt TO:<$rcpt_to>", "250"); // Send DATA command send_command($socket, "DATA", "354"); // Prepare headers $headers = "From: $mail_from\r\n"; $headers .= "To: $rcpt_to\r\n"; $headers .= "Subject: $subject\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n"; $headers .= "Date: " . date('r') . "\r\n"; $headers .= "Message-ID: <" . uniqid() . "@$ehlo_domain>\r\n"; $headers .= "\r\n"; // Empty line to separate headers from body // Show what we're sending echo "<h2>4. Email Content</h2>"; echo "<div class='info'>"; echo "<strong>Headers:</strong><br>"; echo "<pre>" . htmlspecialchars($headers) . "</pre>"; echo "<strong>Body:</strong><br>"; echo "<pre>" . htmlspecialchars($html_body) . "</pre>"; echo "</div>"; // Send headers and body (show what we're sending to socket) echo "<h2>5. Sending Email Data to Socket</h2>"; echo "<div class='info'><strong>Sending headers and body to socket...</strong></div>"; display_response("SENDING HEADERS", $headers, true); fwrite($socket, $headers); display_response("SENDING BODY", $html_body, true); fwrite($socket, $html_body); echo "<h2>6. Ending Data Transmission</h2>"; // End data with \r\n.\r\n send_command($socket, ".", "250"); echo "<h2>7. Closing Connection</h2>"; // Send QUIT send_command($socket, "QUIT", "221"); // Close connection fclose($socket); echo "<div class='success'>"; echo "<h2>✓ EMAIL SENT SUCCESSFULLY!</h2>"; echo "Email sent from <strong>$mail_from</strong> to <strong>$rcpt_to</strong>"; echo "</div>"; } catch (Exception $e) { echo "<div class='error'>"; echo "<h2>✗ ERROR OCCURRED</h2>"; echo "<strong>Error:</strong> " . htmlspecialchars($e->getMessage()); echo "</div>"; if (isset($socket) && $socket) { echo "<div style='margin: 10px 0;'>Attempting to close connection...</div>"; fclose($socket); } echo "</body></html>"; exit(1); } // Additional error handling for socket errors if (isset($socket) && $socket) { $socket_status = stream_get_meta_data($socket); if ($socket_status['timed_out']) { echo "<div class='error'>WARNING: Socket operation timed out</div>"; } if ($socket_status['eof']) { echo "<div class='error'>WARNING: End of file reached on socket</div>"; } } echo "</body></html>"; ?>