Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 06:30
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  MySQL, PostgreSQL, MS SQL, Access (Moderators: Flash-db, Musicman, Ronald Wernecke, Jorge Solis, Andries Seutens)
| | |-+  Extract emailadresses from MYSQL database and use them to send an email
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Extract emailadresses from MYSQL database and use them to send an email  (Read 5066 times)
nasir1123
Server what's that
*
Posts: 15


View Profile
« on: 01/21/09, 08:39 »

Hi all,

I used the Flash-db Guestbook Version 2.0 for my website, but now I got into this problem which I havent been able to solve yet.
I could use a little assistance on that.

What works: after a person posts a comment to a photo he/she will receive an e-mail and also an e-mail will be send to the administrator.

What I'd like to achieve is: after a person posts a comment to a photo, everyone who previously posted a comment on the same photo will receive an e-mail (BCC)

What I need is: a way to extract all e-mailaccounts from the 'email' field in the database table, put them in an array (?) and use them one by one to send an e-mail to (BCC privacy reasons) ; after case 'write'.

Hopefully you guys can help me out. All the variables are making me dizzy Sad


Code:
<?
/*
-----
Application: Flash-dB GuestBook Version 2.0
Details:     mySQL and PHP powered GuestBook
Author:      Mohsin Sumar
Website:     http://www.flash-db.com
Support:     http://www.flash-db.com/Board
Notes:       Coments are marked by using comment entries symbols. Eg: // Comment
-----
*/

// Part One - Initiate a mySQL Database Connection
// Database Connectivity Variables and other Variables
   $DBhost = "localhost";   // Database Server
   $DBuser = "";            // Database User
   $DBpass = "";            // Database Pass
   $DBName = "fotogallerijen";            // Database Name
   $table = "2007_02_01";             // Database Table
   $numComments = 10;       // Number of Comments per page
   
   // Connect to mySQL Server
   $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());
   // Select mySQL Database
   mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

// Part Two - Choose what action to perform
   $action = $_GET['action'];
   
   switch($action) {
      case 'read' :
// Fetch all comments from database table
$sql = 'SELECT * FROM `' . $table . '`';
$allComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numallComments = mysql_num_rows($allComments);
// Fetch page-wise comments from database table
$sql .= ' ORDER BY `time` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments;
$fewComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numfewComments = mysql_num_rows($fewComments);
// Generate Output for Flash to Read
print '&totalEntries=' . $numallComments . '&';
print "<br>&entries=";

if($numallComments == 0) {
    print "Er zijn nog geen berichten achtergelaten...";
} else {
    while ($array = mysql_fetch_array($fewComments)) {
   $name = mysql_result($fewComments, $i, 'name');
   $email = mysql_result($fewComments, $i, 'email');
   $comments = mysql_result($fewComments, $i, 'comments');
   $time = mysql_result($fewComments, $i, 'time');
   $secret = "Verborgen";
   
   print '<b><font color="#FF0000">Name: </b><font color="#666666">' . $name . '<br><b><font color="#FF0000">Comments: </b><font color="#000000">' . $comments . '<br>
<font color="#999999"><i>Date: ' . $time . '</i></font><br><br>';
   $i++;
    }
}
// Print this only when there aren't any more entries..
if($_GET['NumLow'] > $numallComments) {
   print 'No More Entries!&';
}
break;

  case 'write' :
     // Recieve Variables From Flash
$name = ereg_replace("&", "%26", $_POST['yourname']);
$email = ereg_replace("&", "%26", $_POST['youremail']);
$comments = ereg_replace("&", "%26", $_POST['yourcomments']);
$submit = $_POST['submit'];

// Current system date in yyyy-mm-dd format
$submitted_on = date ("Y-m-d H:i:s",time());

// Check if its submitted from Flash
if($submit == 'Yes'){
// Insert the data into the mysql table
$sql = 'INSERT INTO ' . $table .
                ' (`ID`,
   `name`,
   `email`,
   `comments`,
   `time`
  )
  VALUES
  (\'\','
   . '\'' . $name . '\','
   . '\'' . $email . '\','
   . '\'' . $comments . '\','
   . '\'' . $submitted_on . '\'
   )';
$insert = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

// If you want your script to send email to both you and the guest, uncomment the following lines of code
// Email Script Begin


$MyName = "blabla";
$MyEmail = "blabla";
$Subject = "Reactie in fotogallerij";
$EmailBody = "$name heeft de volgende reactie geplaatst bij fotogallerij $table :\n$comments\n\nEmailadres afzender: $email\n\n";

$EmailFooter = "blabla";

$SenderEmailBody = "Beste $name,\nBedankt voor het plaatsen van uw reactie op ...";
$SenderEmailFooter = "Tot ziens op ...";

$Message = $EmailBody.$EmailFooter;
$MyMessage = $SenderEmailBody.$SenderEmailFooter;

mail($MyName." <".$MyEmail.">",$Subject, $Message, "From: ".$name." <".$email.">");
mail($name." <".$email.">",$Subject, $MyMessage, "From: ".$MyName." <".$MyEmail.">");

// Email Script End

print "&gb_status=Bedankt voor uw bericht!.&done=yes&";
return;
}
print "&gb_status=Error!&";
break;
   }
?>
« Last Edit: 01/21/09, 12:24 by Jorge Solis » Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #1 on: 01/21/09, 08:55 »

hi,
how do you know which comment is made to which picture?
This is the main question.

After you got all the users from the list of commentors, you just need to loop through the database with this list.

This is more or less just a sql query with the parameters you know (hopefully) - something like select email from ....
Logged

happy flashing
Cool
Ronald
nasir1123
Server what's that
*
Posts: 15


View Profile
« Reply #2 on: 01/21/09, 11:16 »

Well i gave each photo a different table. So the code I provided in my previous post contains the databasename + exact table corresponding with the photo.
Logged
nasir1123
Server what's that
*
Posts: 15


View Profile
« Reply #3 on: 01/21/09, 14:52 »

To help me on the way:
Whats wrong with this code? I am not a pro at this (yet), so I probably made a few mistakes Sad
If I can manage to make this work, I might be able to help myself.
With the code I intend to get the emailadresses inside the mysql database table and use them for sending an email. In the end I prefer a BCC though.

Code:
<?

   $DBhost = "localhost";   
   $DBuser = "";         
   $DBpass = "";           
   $DBName = "";       
   $table = "2009_01_01";           
   $numComments = 10;     

$DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());

mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());


$query = mysql_query("SELECT email FROM `' . $table . '`");


$email_verzender = "np.eldesperado@gmail.com";
$onderwerp = "Test.";
$bericht = "Kijken of dit werkt, sorry voor het ongemak.";
$headers .= "Bcc: ".$email_verzender."\r\n";


while ($row = mysql_fetch_array($query)) {
mail($row[0], $onderwerp, $bericht, $headers);
}


?>
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #4 on: 01/22/09, 03:34 »

the code looks ok - did you try to execute this query with phpMyAdmin?
Logged

happy flashing
Cool
Ronald
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!