C:\SYSDOC\send_emailaddresses.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors'1);

// Database configuration
$db_host "localhost";
$db_user "admin";
$db_pass "mscmks71s11f132n";
$db_name "niki";

// Create database connection
$conn = new mysqli($db_host$db_user$db_pass$db_name);

// Check connection
if ($conn->connect_error) {
    die(
"Database connection failed: " $conn->connect_error);
}

// Fetch user data
$sql "SELECT u_id, u_name, u_email, u_since FROM users";
$result $conn->query($sql);

$email_body "<h2>GRID TIP User Accounts Email List</h2>";
$email_body .= "<table border='1' border-spacing='15px' style='border-collapse: collapse;'>";
$email_body .= "<tr><th style='padding: 5px'>ID</th><th style='padding: 5px'>Username</th><th style='padding: 5px'>Email Address</th><th style='padding: 5px'>Year</th></tr>";

if (
$result->num_rows 0) {
    while(
$row $result->fetch_assoc()) {
        
// Sanitize output for HTML
    
$id htmlspecialchars($row['u_id']);
        
$username htmlspecialchars($row['u_name']);
        
$email htmlspecialchars($row['u_email']);
    
$year htmlspecialchars($row['u_since']);
        
$email_body .= "<tr><td style='padding: 5px'>{$id}</td><td style='padding: 5px'>{$username}</td><td style='padding: 5px'>{$email}</td><td style='padding: 5px'>{$year}</td></tr>";
    }
} else {
    
$email_body .= "<tr><td colspan='4' style='padding: 5px'>No records found</td></tr>";
}

$email_body .= "</table>";
$conn->close();

// Email configuration
$to "mam@heimam.at";
$subject "GRID TIP User Accounts Email List";
$headers "From: admin.gridtip@gridtip.net\r\n";
$headers .= "Reply-To: admin.gridtip@gridtip.net\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

// Send email
if (mail($to$subject$email_body$headers)) {
    echo 
"Email successfully sent to {$to}";
} else {
    echo 
"Failed to send email. Check your local SMTP configuration.";
}
?>