I have wrote a script for sending newsletter emails, but it doesn't work, and I dont' know why
here is the code:
$subject = $_POST['subject'];
$body = $_POST['body'];
$headers = "From: no-reply@mywebsite.com
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
try {
$stmt = $db->prepare("SELECT * FROM `newsletter`");
$stmt->execute();
foreach($stmt as $row) {
if(mail($row['email'], $subject, $body, $headers)) {
echo "The email to " . $row['email'] . " was <font color=\"green\">successfully sent</sent>.<br />";
} else {
echo "The email to " . $row['email'] . " <font color=\"red\">failed</font>.<br />";
}
}
} catch (PDOException $e) {
echo "<p><b>Sorry the connection to the database failed with: {$e->getMessage()}</b></p>";
}
When I run the code, the email seems sent, but my mailbox is empty
Thanks in advance