LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-22-2008, 02:38 AM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
send output of mysql query to email within same script


I have some code in a php script which produces a table of results. Whats the best and simplest way to send this via email within the same php script?

I dont really want to pipe the output to a text file then use 'mail' from within the system.

Code:
// Display Report title
print "Report\n====================\n";
// Display column headings
print "Host\t\tCount\n";

// Fetch and display the results
while ($result_row = mysql_fetch_row(($result)))
{

printf($result_row[0]);
print "\t";
printf($result_row[1]);
print "\n";

}
regards,
 
Old 11-22-2008, 06:53 PM   #2
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Create a variable called mailtxt and use the .= to keep appending the results. Then use the built in mail function for email. That should get what you want.

Code:
// Display Report title
$mailtxt;
$mailtxt .= "Report\n====================\n";
// Display column headings
$mailtxt .= "Host\t\tCount\n";

// Fetch and display the results
while ($result_row = mysql_fetch_row(($result)))
{
 global $mailtxt;
$mailtxt .= $result_row[0];
$mailtxt .= "\t";
$mailtxt .= $result_row[1];
$mailtxt .= "\n";

}

$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$subject = "Subject for reviever"; //subject

mail($recipient, $subject, $mailtxt); //mail command :)
this code should be a start.
 
Old 12-03-2008, 03:14 AM   #3
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
thanks mate. works perfectly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql use output of one query in another query secretlydead Programming 2 11-19-2007 01:25 AM
how to send the output of cronjobs to another email address ? kirtikjr Linux - Software 1 07-12-2007 05:36 PM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 12:43 PM
Send query string via MIRC script cadj Programming 0 08-25-2004 06:25 AM
cron to run a an sql query and send Email ehsan Linux - General 2 03-14-2001 10:50 PM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration