gideon107540
-
Posts
1 -
Joined
-
Last visited
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Send message to all email addresses in database table
in PHP Coding Help
Posted
<?php
// Database connection
$servername = "localhost";
$username = "u880577714_enbullsnbears";
$password = "Olagoro4";
$dbname = "u880577714_enbullsnbears";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Retrieve email addresses
$stmt = $conn->prepare("SELECT email FROM user");
$stmt->execute();
$emails = $stmt->fetchAll(PDO::FETCH_COLUMN);
// Send emails
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: support@en.bullsnbearstraders.online";
foreach ($emails as $email) {
mail($email, $subject, $message, $headers);
echo "Email sent to: $email<br>";
}
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>