|
3 | 3 | ini_set('display_errors', 1); |
4 | 4 | error_reporting(E_ALL); |
5 | 5 |
|
6 | | -echo "<h1>Email Sending Test</h1>"; |
| 6 | +echo "<h1>Email Connectivity & Sending Test</h1>"; |
7 | 7 |
|
8 | 8 | // Load configuration |
9 | 9 | require_once 'config/email.php'; |
|
12 | 12 | use PHPMailer\PHPMailer\PHPMailer; |
13 | 13 | use PHPMailer\PHPMailer\Exception; |
14 | 14 |
|
15 | | -echo "<p>Configuration Loaded.</p>"; |
| 15 | +$host = SMTP_HOST; |
| 16 | +$ports = [587, 465]; |
| 17 | + |
| 18 | +// 1. DNS Resolution Test |
| 19 | +echo "<h2>1. DNS Resolution</h2>"; |
| 20 | +$ip = gethostbyname($host); |
| 21 | +echo "Resolved <strong>$host</strong> to IPv4: <strong>$ip</strong><br>"; |
| 22 | + |
| 23 | +// 2. Port Connectivity Test |
| 24 | +echo "<h2>2. Port Connectivity</h2>"; |
| 25 | +foreach ($ports as $port) { |
| 26 | + echo "Testing connection to <strong>$host:$port</strong>... "; |
| 27 | + $fp = @fsockopen($host, $port, $errno, $errstr, 5); |
| 28 | + if ($fp) { |
| 29 | + echo "<span style='color:green'>SUCCESS</span><br>"; |
| 30 | + fclose($fp); |
| 31 | + } else { |
| 32 | + echo "<span style='color:red'>FAILED ($errno: $errstr)</span><br>"; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +// 3. Email Sending Test |
| 37 | +echo "<h2>3. Sending Test</h2>"; |
| 38 | + |
16 | 39 | echo "<ul>"; |
17 | 40 | echo "<li>Host: " . SMTP_HOST . "</li>"; |
18 | 41 | echo "<li>Port: " . SMTP_PORT . "</li>"; |
19 | 42 | echo "<li>Username: " . (SMTP_USERNAME ? 'Set' : 'Not Set') . "</li>"; |
20 | | -echo "<li>Password: " . (SMTP_PASSWORD ? 'Set' : 'Not Set') . "</li>"; |
21 | 43 | echo "</ul>"; |
22 | 44 |
|
23 | 45 | $mail = new PHPMailer(true); |
24 | 46 |
|
25 | 47 | try { |
26 | 48 | // Server settings |
27 | | - $mail->SMTPDebug = 2; // Enable verbose debug output |
28 | | - $mail->isSMTP(); // Send using SMTP |
29 | | - $mail->Host = SMTP_HOST; // Set the SMTP server to send through |
30 | | - $mail->SMTPAuth = SMTP_AUTH; // Enable SMTP authentication |
31 | | - $mail->Username = SMTP_USERNAME; // SMTP username |
32 | | - $mail->Password = SMTP_PASSWORD; // SMTP password |
33 | | - $mail->SMTPSecure = SMTP_SECURE; // Enable implicit TLS encryption |
34 | | - $mail->Port = SMTP_PORT; // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` |
| 49 | + $mail->SMTPDebug = 2; |
| 50 | + $mail->isSMTP(); |
| 51 | + |
| 52 | + // FORCE IPv4 workaround if standard host fails |
| 53 | + // $mail->Host = gethostbyname(SMTP_HOST); |
| 54 | + $mail->Host = SMTP_HOST; |
| 55 | + |
| 56 | + $mail->SMTPAuth = SMTP_AUTH; |
| 57 | + $mail->Username = SMTP_USERNAME; |
| 58 | + $mail->Password = SMTP_PASSWORD; |
| 59 | + $mail->SMTPSecure = SMTP_SECURE; |
| 60 | + $mail->Port = SMTP_PORT; |
| 61 | + |
| 62 | + // Timeout settings |
| 63 | + $mail->Timeout = 10; |
| 64 | + $mail->Timelimit = 10; |
35 | 65 |
|
36 | 66 | // Recipients |
37 | 67 | $mail->setFrom(MAIL_FROM_EMAIL, MAIL_FROM_NAME); |
38 | | - // Send to the sender for testing |
39 | 68 | $mail->addAddress(SMTP_USERNAME); |
40 | 69 |
|
41 | 70 | // Content |
42 | | - $mail->isHTML(true); // Set email format to HTML |
| 71 | + $mail->isHTML(true); |
43 | 72 | $mail->Subject = 'Test Email from Smart Tailoring'; |
44 | 73 | $mail->Body = 'This is a test email to verify SMTP configuration on Render.'; |
45 | | - $mail->AltBody = 'This is a test email to verify SMTP configuration on Render.'; |
46 | 74 |
|
47 | 75 | echo "<p>Attempting to send email...</p>"; |
48 | 76 | $mail->send(); |
|
0 commit comments