Jump to content

is there a way to pull email address from a db and content of email from db?


j5uh

Recommended Posts

is there a way to pull email address from a db and content of email from db?

 

i need to have an email go out every day at 5pm to a select group of people that are stored in a database. the content is updated every single day so I need it to go out everyday at 5pm. Anyone know how I can achieve this?

In a PHP script:

Step 1) Query the database and put together the contents of the email based on what is in the database.

            http://www.php.net/mysql

Step 2) Query the list of email addresses from the database

Step 3) Send the email using mail()

            http://www.php.net/mail

 

On ther server:

Step 4) Setup a cronjob (unix) or a scheduled task (windows) to run the above script at 5pm every day

 

so I've put this script together

 

 <?php 
include("config.php");
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);

$sql = "SELECT $db_usernamefield, $db_emailfield FROM $db_table";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result)){
$username = $row['username'];
$email = $row['email'];

$message = '
<html>
<head>
<title>The title of your e-mail text area goes here</title>
</head>
<body>
<p>The conte would go here.</p>
</body>
</html>
';

$mailhead = 'MIME-Version: 1.0' . "\n";
$mailhead .= 'Content-type: text/html; charset=UTF-8' . "\n";
$mailhead .= "From: $fromname\n";

if(mail ($email, $emailsubject, $message, "From: $fromname <$fromemail>", $mailhead))
echo "Messages sent";
}
?>

 

for the life of me I can't get this to send an HTML email. It just spits out the html codes. What ma I doing wrong?

 

Also it sends the email twice instead of just once.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.