j5uh Posted March 28, 2008 Share Posted March 28, 2008 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? Link to comment https://forums.phpfreaks.com/topic/98367-is-there-a-way-to-pull-email-address-from-a-db-and-content-of-email-from-db/ Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/98367-is-there-a-way-to-pull-email-address-from-a-db-and-content-of-email-from-db/#findComment-503448 Share on other sites More sharing options...
j5uh Posted March 28, 2008 Author Share Posted March 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/98367-is-there-a-way-to-pull-email-address-from-a-db-and-content-of-email-from-db/#findComment-503531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.