Jump to content

Using a php file to send e-mail to all e-mailaccounts in MYSQL database


Recommended Posts

I apologize in advance for being a newb at this. I have to admit I saw in an other thread a simular problem, but since I am not good at coding, I didn't manage to tune it into my needs :( Hopefully someone can guide me into the right direction. My problem is that I know some stuff about Flash and the php coding is sometimes just a neccassary evil to me hehe.

 

So: I got this website where I posts pictures, videos and such, pretty random ofcourse. People can leave a message with each photo and or video. Also pretty random, nothing special. Since my website is 100% flash and I am not a pro coder, it took me some time to fix something that works pretty well for my website. Ofcourse I didn't write the whole code myself (since I am not a pro). What I would like to do now is to add a small amount of code to notify previous responders that someone has posted a new message, an e-mail. So this piece of code needs to extract all e-mailadresses from the correct table in the mysql database and use it to send an e-mail notification.

Down here you can find the code I am using for each photo. Each photo has its own table in a database. Since I admit I am newb at this, I didn't bother to leave out all comments etc. I did delete my personal info tho.

 

This php file gets launched as soon as someone is leaving a note on my flash website at a particular photo or video and thus sends some variables to the database. At the bottom part of the code you will find a script which will send an email to the one who just left a message and an email to the administrator of the site. This is all fine. But my goal is to also send an email to the users that are already stored within the database table.

 

Please help me!! Many thanks in advance.

 

<?
/* 
-----
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 = "mydatabasename";            // Database Name
   $table = "2008_16_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 = "Name of my website";
	 $MyEmail = "[email protected]";
	 $Subject = "Reactie in fotogallerij";
	 $EmailBody = "$name heeft de volgende reactie geplaatst bij fotogallerij $table :\n$comments\n\nEmailadres afzender: $email\n\n";

	 $EmailFooter = "www.mywebsite.nl";

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

	 $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;
   }
?>

Well depends on how you look at it. I have learned most of my actionscript for flash this way. Sometimes, at least I have that, it can take forever to master a code, but if you have a code ready and you are looking at it, you begin to see how it all works. The code I pasted in this thread wasn't the original code, I did manage to change a lot of things to make it work. Now I do not believe that I have done a great job on doing that, but since my website is primary about the flash part, you sometimes have to make choices in what you master and what not. For me it's the only piece of code missing.

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.