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.
Ta Chris.
Anything at http://www.hotscripts.com/PHP/Scripts_and_Programs/Mailing_List_Managers/index.html you could use?
http://www.php.net/mail if you wanna do it yourself.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?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><b r>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><b r>SQL Error No.: <b>".mysql_errno()."</b>") ;
// Now we can display results.
$sql = "SELECT * FROM maillist";
$sql_result = mysql_query($sql,$connecti on) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><b r>SQL Error No.: <b>".mysql_errno()."</b>") ;
while($row=mysql_fetch_arr ay($sql_re sult)){
$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>B ig 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,$subj ect,$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();
}
}
?>
/*
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",
//Select Table
$db = mysql_select_db("dbname", $connection) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><b
// Now we can display results.
$sql = "SELECT * FROM maillist";
$sql_result = mysql_query($sql,$connecti
while($row=mysql_fetch_arr
$to = $row[\"name\"]."<".$row[\"
$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>
// 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,$subj
/* 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();
}
}
?>