Hey guys. I thought this was hard because I’m an uber-beginner to PHP/MySQL (3rd day!!). Now, after a good 6 hours of searching the web, asking all my script buddies, and good ol’ trial and error, I have come to the conclusions that this is, in fact, a difficult thing to do.
I am trying to send out a nice HTML formatted email from a PHP script that sends to all emails in a database. The HTML mail also grabs data from a db as well. I have tried with and without the added php code, many different ways of settign up the file, and even without the html. No matter what i do i get an error. if anyone can help me build a working file that sends html emails i will be eternally grateful. I stripped the script down to the bare minimum, which is what youll see here. i need to have that loop there to get all the emails in the db but it seems to be clashing with the headers. (the script works fine without the headers added).
<?
mysql_connect ("localhost", "user", "pass");
mysql_select_db ("database");
$sql = "SELECT * FROM redmail";
$result = mysql_query($sql);
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";
While ($row = mysql_fetch_array($result))
{
$email = $row['email'];
$success = mail("$email","$subject","$message","$headers","From: [email][email protected][/email]");
if ($success)
echo "The newsletter was successfully sent<br />";
else
echo "An error occurred when sending the newsletter<br />";
}
mysql_close();
?>
thanks in advance!