# Local Server SMTP Documentation ## Overview The Local Server SMTP functionality in the Campaign application provides a simplified way to send emails directly through the server's built-in mail service without requiring external SMTP credentials. This document explains how the Local Server SMTP works, its configuration, and how it differs from other SMTP options. ## How Local Server SMTP Works The Local Server SMTP option uses the server's direct SMTP service on port 25 without requiring authentication. This is ideal for installations where the campaign application is hosted on the same server that handles mail delivery. ### Key Features 1. **No Authentication Required**: Unlike regular SMTP or Mailrelay, Local Server SMTP doesn't require username or password. 2. **Direct Server Communication**: Uses the server's IP address or 'localhost' as the SMTP server. 3. **Port 25**: Always uses the standard SMTP port 25. 4. **No Encryption**: Uses no encryption ('none') since it's communicating directly with the local mail service. 5. **Automatic Configuration**: Automatically detects the server's IP address or falls back to 'localhost'. ## Configuration in smtp_settings.php When a user selects the 'local' server type in the SMTP settings form, the application automatically configures the following settings: ```php // Local server settings - automatically use server IP and port 25 $server_ip = $_SERVER['SERVER_ADDR'] ?? 'localhost'; // Use the server's IP address directly $data['smtp_server'] = $server_ip; $data['port'] = 25; $data['encryption'] = 'none'; $data['username'] = ''; $password = ''; ``` This configuration ensures that: - The SMTP server is set to the server's IP address or 'localhost' - The port is set to 25 - No encryption is used - No username or password is required ## Implementation in bulk_email.php When sending emails through the Local Server SMTP, the application configures PHPMailer with specific settings: ```php // Configure based on SMTP type if ($smtp_settings['type'] === 'local' || $smtp_settings['type'] === 'amazon_ec2') { // Local server or Amazon EC2 - no authentication needed $mail->SMTPAuth = false; $mail->SMTPAutoTLS = false; // Disable auto TLS for port 25 $mail->SMTPSecure = ''; // No encryption $mail->Port = 25; // Add debug options for local server $mail->SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]; // Log server configuration error_log("Using direct server SMTP: " . $mail->Host . ":" . $mail->Port); error_log("Authentication: Disabled"); error_log("Encryption: None"); error_log("SMTPAutoTLS: Disabled"); } ``` Key settings for Local Server SMTP: - `SMTPAuth = false`: Disables SMTP authentication - `SMTPAutoTLS = false`: Prevents PHPMailer from automatically upgrading to TLS - `SMTPSecure = ''`: No encryption is used - `Port = 25`: Uses the standard SMTP port ## Comparison with Other SMTP Options | Feature | Local Server | Regular SMTP | Mailrelay | Amazon EC2 | |---------|--------------|--------------|-----------|------------| | Authentication | No | Yes | Yes | No | | Server | Server IP/localhost | Custom | smtp1.s.ipzmarketing.com | localhost | | Port | 25 | 465/587 | 587 | 587 | | Encryption | None | SSL/TLS | TLS | TLS | | Username/Password | Not required | Required | Required | Not required | | Best for | Same-server hosting | Regular emails | Bulk emails | AWS hosting | ## Why Local Server SMTP Works When Others Don't The Local Server SMTP option works reliably because: 1. **No Authentication Issues**: Since it doesn't require authentication, there are no credential problems. 2. **Direct Communication**: It communicates directly with the server's mail service without intermediaries. 3. **No Encryption Complications**: It avoids SSL/TLS negotiation issues that can occur with encrypted connections. 4. **Simple Configuration**: The minimal configuration reduces points of failure. ## Troubleshooting If you're experiencing issues with other SMTP options but Local Server SMTP works: 1. **Check Server Configuration**: Ensure your server has a properly configured mail service. 2. **Verify Port 25 is Open**: Some hosting providers block port 25; confirm it's open. 3. **Check for IP Restrictions**: Some mail services restrict which IPs can send mail. 4. **Review Mail Logs**: Check server mail logs for any delivery issues. ## Implementation in get_smtp_settings() The `get_smtp_settings()` function in `includes/functions.php` prioritizes finding and using Local Server SMTP settings: ```php // If no active SMTP found, try to find a local server type if (!$settings) { $query = "SELECT * FROM smtp_settings WHERE type = 'local' LIMIT 1"; $localSettings = $db->fetch($query); if (!empty($localSettings)) { // Set local server as active error_log("Found local server SMTP, setting as active"); $db->query("UPDATE smtp_settings SET is_active = 1 WHERE id = ?", [$localSettings['id']]); $settings = $localSettings; } } ``` This ensures that if no active SMTP configuration is found, the system will look for and activate a Local Server SMTP configuration if available. ## Conclusion The Local Server SMTP option provides a reliable, simple way to send emails when the campaign application is hosted on the same server that handles mail delivery. It bypasses many common SMTP issues by using direct server communication without authentication or encryption requirements. For installations where the application and mail service are on the same server, Local Server SMTP should be the preferred option due to its simplicity and reliability.