Jump to content

Recommended Posts

I have created this small script to email rows from mysql database.

 

 

<?php

include_once('include/database.php');            // Database connection details

include_once('include/database.class.php');          // access database functions

$db=new database(DBHOST,DBNAME,DBUSER,DBPASS);    //  database connection

 

$sql=mysql_query("SELECT * FROM news ORDER BY newsId LIMIT 0,5") or die (mysql_error());

while($del=mysql_fetch_assoc($sql)){

$id = $del['newsId'];

$content = $del['content'];

$title = $del['title'];

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

?>

 

<?php 

mail( "someguy@gmail.com", "$title", $content, "$headers" );

 

 

$sql3="DELETE FROM news WHERE newsId='".$del['newsId']."'";

 

 

$res=mysql_query($sql3)or die (mysql_error());

 

}

 

?>

It works great just like i wanted, sends 5 email from table 'news' based on ascending numbers in row 'newsId'.

 

but i would like to make a change now, i would like the script to send one email each to different email id's from the row "email" in the table "emailaddress" randomly.

 

So that in case there is only 3 rows of content in "news" table the email is sent to random 3 email address from the table "email address".

 

I have tried lot of things but i just can't find any working solution.

Link to comment
https://forums.phpfreaks.com/topic/176002-solved-issues-with-my-email-script/
Share on other sites

thanks for your reply :D I was in a rush that time.

 

I wanted my script to send 1 email each to the 5 random email id picked from fields in a row.

 

I fixed it myself, just had to create a new variable for email id and call it inside the loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.