Click to See Complete Forum and Search --> : Making my own newsletter


mazazino
07-18-2007, 12:13 PM
Hi all, I'm a new member and I just wanna ask you guys something..maybe some of u can help me out..
I'm working in a company that wants to make its own a newsletter, and we have this database of almost 15000 emails that we want to send a newsletter to every now and then. We've worked on several websites but a newsletter, never. So we're trying to figure out what the procedure for writing our own newsletter in php, so if any of you guys has some sort of a tutorial or a website that we could use, or maybe some of your own experiences, it would be helpful..Thanks..

foxbeefly
07-26-2007, 07:25 AM
Assuming you have a table called customers with at least the fields customer_name and customer_mail in a MySQL database, something like this should work:

<?php
session_start();
// database access parameters for database
$host = 'localhost';
$user = 'your_user';
$pass = 'your_pass';
$db = 'your_database';

//connect to db
$connection = mysql_connect($host, $user, $pass) or die('ERROR: Unable to connect!');
// select database
mysql_select_db($db) or die('ERROR: Unable to select database!');


$query = 'SELECT * FROM customers';
$result = mysql_query($query) or die('ERROR: $query. '.mysql_error());

while($row = mysql_fetch_object($result)) {

//send email to company
$to = $row->customer_mail;
$subject = "Customer Email";
$body = "<html><head><style>
<!--
h1,h2 { color: #808080; font-family: Tahoma; font-size: 14pt; font-weight: bold }
body {margin-top:0; margin-left:50px; font-family: Tahoma;}
#container {width:800px; background-color:#9CA6B5;}
#container div {margin-left:50px; margin-right:50px}
-->
</style>
</head><body><div id='container'><img src='http://www.your_domain/images/mail_top.gif' />
<div><h1>You have received a message from the Sobhar Website</h1>
<h1>Dear ".$row->customer_name."</h1>
<p>Email: ".$row->customer_mail."</p>
<p>We love you! You are our greatest customer ever!</p></div>
<img src='http://www.your_domain/images/mail_bottom.gif' /></div></body></html>";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'Reply-To: me@your_domain.com' . "\r\n";
$headers .= 'From: Me <me@your_domain.com>' . "\r\n";
$headers .= 'Bcc: me@your_domain.com' . "\r\n";
mail($to, $subject, $body, $headers))
};
?>

Not sure what would happen with those kind of numbers though to be honest!