Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-22-2008, 03:38 AM   #1
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.

// 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)))

print "\t";
print "\n";

Old 11-22-2008, 07:53 PM   #2
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.

// Display Report title
$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 = ""; //senders e-mail adress
$recipient = ""; //recipient
$subject = "Subject for reviever"; //subject

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

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


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 02:25 AM
how to send the output of cronjobs to another email address ? kirtikjr Linux - Software 1 07-12-2007 06:36 PM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 01:43 PM
Send query string via MIRC script cadj Programming 0 08-25-2004 07:25 AM
cron to run a an sql query and send Email ehsan Linux - General 2 03-14-2001 11:50 PM > Forums > Linux Forums > Linux - Newbie

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

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