Jump to content

Database to Email


mbradley

Recommended Posts

Ok I have looked and looked and tried on my own but my .. well i am limited on what i know about it... prolly somthing simple... but here goes:

 

I have right now information that is in my database that I want to email to someone.. I have it already setup for times and such... BUT i can't seem to get the information that i have in there to come up?

<?php
define('_VALID_INCLUDE', TRUE);
include 'lib/config.php';
include 'lib/opendb.php';
switch(strtoupper($_REQUEST['command'])){
        case 'EMAIL':
        cmd_emailall($_REQUEST);
        break;
        default:
	index($_REQUEST);
}

//function cmd_email($params){
function index($params){


//define the receiver of the email
$to = 'mbradley1980@gmail.com';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I am trully sorry but your email does not allow HTML to be coded in it. Please change it as this requires you to have
a true HTML in it to view the information properly.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php
$sql = "SELECT * FROM `VisitTracker` ORDER BY `VisitTracker`.`vtime` DESC ";
	$result = mysql_query($sql) or die(mysql_error());  
	$sql_count = 'SELECT COUNT(*) FROM VisitTracker';
	$count = mysql_query($sql_count) or die(mysql_error());

	echo mysql_num_rows($result); 

	echo "<table border='1'>";
echo "<tr><th>Name</th><th>UUID</th><th>Distance</th><th>Time</th><th>sensor</th><th>SIM</th><th>Owner</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><center>"; 
echo $row[vname];
echo "</center></td><td>"; 
echo $row[vuuid];
echo "</td><td>";
echo $row[vdist];
echo "</td><td>"; 	
echo $row[vtime];
echo "</td><td>"; 
echo $row[vsensor];
echo "</td><td>"; 
echo $row[vsim];
echo "</td><td>"; 
echo $row[vowner];
echo "</td></tr>"; 
} 

	echo "</table><center><br><br>";
	echo 'Created for us with Second Life<br>Saladin NightFire<br>Wolf Creations';
	echo "</center>";
	}
?> 

--PHP-alt-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
echo $message;
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";}
?>

NOW this is what comes up : On page and email is blank:(  HELP ME PLEASE

 

--PHP-alt-b210121e536f5f239385577633f9110f Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I am trully sorry but your email does not allow HTML to be coded in it. Please change it as this requires you to have a true HTML in it to view the information properly. --PHP-alt-b210121e536f5f239385577633f9110f Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --PHP-alt-b210121e536f5f239385577633f9110f-- Mail sent

Link to comment
Share on other sites

Firstly:

mail()'s boolean return value doesn't necessarily indicate whether or not a message was sent, it just shows whether or not YOUR mail server got the message.

 

Secondly:

Can we see the two included files?

 

Thirdly:

You spelled "truly" incorrectly in the e-mail body. =)

Link to comment
Share on other sites

yea the includes are just the basic connect to database and such .. let me put them below..

 

config.php

<?php
defined('_VALID_INCLUDE') or die('Direct access not allowed.');
// Database Settings
define('DB_HOST','****');       // MySQL Server Host
define('DB_USER','SecondLifeDB');     // MySQL User
define('DB_PASS','****');                // MySQL Password
define('DB_NAME','SecondLifeDB');          //The name of the database
?>

opendb.php

<?php
defined('_VALID_INCLUDE') or die('Direct access not allowed.');
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME,$db) or die(mysql_error());
?>

 

And i appreciate the humor:)  Been working on this for so long i am getting pissed bc i dunno what i am missing or anything:(

suppose to been simple to just email the info from the database to the email... and nothing:(

 

Link to comment
Share on other sites

You can remove:

echo $message;

If you don't want it to echo it.

 

Why are you passing $_REQUEST to the function?  Why aren't you sanitizing the data?

 

Echo was just to use for debug bc the email was empty and was checking to make sure it was passing the information..

 

and .. sanitizing and request i am not sure...:(  i am just ... well been working on it so long i dunno what i have done wrong:( 

 

ohh the request i had that from a previous attempt... but it should hurt it should it?

 

edit: I seen why i did it ... right now that is not suppose to be able to have a index it is suppose to be getting the information from the request.... This is getting a request from Second life.. and then it will check the database on there name and then it will send that info to the email

 

Link to comment
Share on other sites

<?php
define('_VALID_INCLUDE', TRUE);
include 'lib/config.php';
include 'lib/opendb.php';
switch(strtoupper($_REQUEST['command'])){
        case 'EMAIL':
        cmd_emailall($_REQUEST);
        break;
        default:
	index($_REQUEST);
}

//function cmd_email($params){
function index($params){


//define the receiver of the email
$to = "mbradley1980@gmail.com";
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I am trully sorry but your email does not allow HTML to be coded in it. Please change it as this requires you to have
a true HTML in it to view the information properly.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php
$sql = "SELECT * FROM `VisitTracker` ORDER BY `VisitTracker`.`vtime` DESC ";
	$result = mysql_query($sql) or die(mysql_error());  
	$sql_count = 'SELECT COUNT(*) FROM VisitTracker';
	$count = mysql_query($sql_count) or die(mysql_error());

	echo mysql_num_rows($result); 

	echo "<table border='1'>";
echo "<tr><th>Name</th><th>UUID</th><th>Distance</th><th>Time</th><th>sensor</th><th>SIM</th><th>Owner</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><center>"; 
echo $row[vname];
echo "</center></td><td>"; 
echo $row[vuuid];
echo "</td><td>";
echo $row[vdist];
echo "</td><td>"; 	
echo $row[vtime];
echo "</td><td>"; 
echo $row[vsensor];
echo "</td><td>"; 
echo $row[vsim];
echo "</td><td>"; 
echo $row[vowner];
echo "</td></tr>"; 
} 

	echo "</table><center><br><br>";
	echo 'Created for us with Second Life<br>Saladin NightFire<br>Wolf Creations';
	echo "</center>";
	}
?> 

--PHP-alt-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
//echo $message;
$mail_sent = mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

now i am getting a server error with this code... so i am truly LOST:(

 

also it is passing the right things in the message but not still getting on email

 

Link to comment
Share on other sites

Ok well now i am getting a 500 error and i am not sure y:(  Can someone help me out on this? above is the include files... but all are the same but below....

 

 

Here is the idea... From secondlife the script will get a request to send a email to the person ... with a check with there name to the owner ... and then if passed it will send the information that is in the database to teh email.... Soo i dunno if that helps.. but i am lost now as to what to do:(

 

PLEASE PLEASE PLEASE

 

 

<?php
define('_VALID_INCLUDE', TRUE);
include 'lib/config.php';
include 'lib/opendb.php';
switch(strtoupper($_REQUEST['command'])){
        case 'EMAIL':
        cmd_emailall($_REQUEST);
        break;
        default:
	index($_REQUEST);
}

//function cmd_email($params){
function index($params){
$sql = "SELECT * FROM `VisitTracker` ORDER BY `VisitTracker`.`vtime` DESC ";
	$result = mysql_query($sql) or die(mysql_error());  
	$sql_count = 'SELECT COUNT(*) FROM VisitTracker';
	$count = mysql_query($sql_count) or die(mysql_error());


//define the receiver of the email
$to = "mbradley1980@gmail.com";
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I am trully sorry but your email does not allow HTML to be coded in it. Please change it as this requires you to have
a true HTML in it to view the information properly.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php
$sql = "SELECT * FROM `VisitTracker` ORDER BY `VisitTracker`.`vtime` DESC ";
	$result = mysql_query($sql) or die(mysql_error());  
	$sql_count = 'SELECT COUNT(*) FROM VisitTracker';
	$count = mysql_query($sql_count) or die(mysql_error());

	echo mysql_num_rows($result); 

	echo "<table border='1'>";
echo "<tr><th>Name</th><th>UUID</th><th>Distance</th><th>Time</th><th>sensor</th><th>SIM</th><th>Owner</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td><center>"; 
echo $row[vname];
echo "</center></td><td>"; 
echo $row[vuuid];
echo "</td><td>";
echo $row[vdist];
echo "</td><td>"; 	
echo $row[vtime];
echo "</td><td>"; 
echo $row[vsensor];
echo "</td><td>"; 
echo $row[vsim];
echo "</td><td>"; 
echo $row[vowner];
echo "</td></tr>"; 
} 

	echo "</table><center><br><br>";
	echo 'Created for us with Second Life<br>Saladin NightFire<br>Wolf Creations';
	echo "</center>";
	}
?> 

--PHP-alt-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
//echo $message;
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Link to comment
Share on other sites

Out of curiosity.. what's the point of the following code?:

 

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I am trully sorry but your email does not allow HTML to be coded in it. Please change it as this requires you to have
a true HTML in it to view the information properly.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Link to comment
Share on other sites

that code is there to allow those who only allow plain text in emails.... that is all:)  LOL 

 

But i guess that no one can help me on this?  it is getting to the point where it is ... well getting on my nerves... bc i can't simply put the information on the database in a email msg and mail it ...:(

Link to comment
Share on other sites

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.