Skip to content

Commit 49e05ca

Browse files
Update email test with connectivity checks
1 parent c125a39 commit 49e05ca

1 file changed

Lines changed: 42 additions & 14 deletions

File tree

test_email.php

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ini_set('display_errors', 1);
44
error_reporting(E_ALL);
55

6-
echo "<h1>Email Sending Test</h1>";
6+
echo "<h1>Email Connectivity & Sending Test</h1>";
77

88
// Load configuration
99
require_once 'config/email.php';
@@ -12,37 +12,65 @@
1212
use PHPMailer\PHPMailer\PHPMailer;
1313
use PHPMailer\PHPMailer\Exception;
1414

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+
1639
echo "<ul>";
1740
echo "<li>Host: " . SMTP_HOST . "</li>";
1841
echo "<li>Port: " . SMTP_PORT . "</li>";
1942
echo "<li>Username: " . (SMTP_USERNAME ? 'Set' : 'Not Set') . "</li>";
20-
echo "<li>Password: " . (SMTP_PASSWORD ? 'Set' : 'Not Set') . "</li>";
2143
echo "</ul>";
2244

2345
$mail = new PHPMailer(true);
2446

2547
try {
2648
// 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;
3565

3666
// Recipients
3767
$mail->setFrom(MAIL_FROM_EMAIL, MAIL_FROM_NAME);
38-
// Send to the sender for testing
3968
$mail->addAddress(SMTP_USERNAME);
4069

4170
// Content
42-
$mail->isHTML(true); // Set email format to HTML
71+
$mail->isHTML(true);
4372
$mail->Subject = 'Test Email from Smart Tailoring';
4473
$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.';
4674

4775
echo "<p>Attempting to send email...</p>";
4876
$mail->send();

0 commit comments

Comments
 (0)