Link to home
Start Free TrialLog in
Avatar of icb01co1
icb01co1

asked on

HTML Mail

I need to create a php program that will let me e-mail everyone i have in a database. I want to e-mail a HTML news letter but i dont know how.

Ta Chris.
Avatar of KenAdney
KenAdney

http://www.php.net/mail if you wanna do it yourself.
ASKER CERTIFIED SOLUTION
Avatar of wise0ne
wise0ne
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<?php

/*
Table Scheme
CREATE TABLE `maillist` (
`id` INT( 3 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 100 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
INDEX ( `id` ) ,
UNIQUE ( `email` )
);

*/

//Connect to Databases
$connection = mysql_connect("localhost", "username", "password") or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

//Select Table
$db = mysql_select_db("dbname", $connection) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

// Now we can display results.
$sql = "SELECT * FROM maillist";
$sql_result = mysql_query($sql,$connection) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

while($row=mysql_fetch_array($sql_result)){
 $to = $row[\"name\"]."<".$row[\"email\"].">";
 
 $headers ="From: webmaster@example.comrn";
 $headers .= "MIME-Version: 1.0rn";
 $headers .= "Content-type: text/html; charset=iso-8859-1rn";
 $subject ="Regarding whatever";
 $body="<html><head></head><body><b>Big Bold HTML Message</b></body></html>";

 // Now we send the message
 //We set a variable equal to the mail() function in order to capture success or fail.
 $send_check=mail($to,$subject,$body,$headers);

 /* It is important to note that while the mail() function will return
 a boolean false if it is unable to pass the message off to be sent.
 This is NOT a guarantee that the message will actually be sent
 or arrive somewhere. When using mail() for real, this checking
 is rarely done. It is included here only for completeness.
 */
 if ($send_check!=true)
 {
 echo 'An error occurred while sending mail.';
 die();
 }
}
?>