Hello everyone!
I've created a mailing list where users can subscribe with a form, and the results are added to a MySQL database. They can also unsubscribe. The subscribe/unsubscribe pages work GREAT, but the page where I send out the email is giving me some trouble. It says that the email was sent, but the users never get it! Any suggestions?
The PHP for the send_email.php page is:
<?php
$from = 'me@example.com';
$subject = $_POST['subject'];
$text = $_POST['body'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$dbc = mysqli_connect('db.server.com', 'my_username', 'my_password', 'my_database')
or die('Error: Could not connect to database');
$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query)
or die('Error: Could not connect to database');
while ($row = mysqli_fetch_array($result)){
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$to = $row['email'];
$msg = "Hello $first_name!<br /><br />$text<br /><br />This message was sent to $first_name $last_name ($to) because they signed up to my email list<br />Don't want to receive these emails? Click <a href='http://my-site.com/mailing-list/remove.php?email=$to' title='Unsubscribe'>here</a> to unsubscribe.";
mail($to, $subject, $msg, $headers, 'From:' . $from);
echo 'Email sent to: ' . $to . '<br />';
}
mysqli_close($dbc);
?>
Thanks!