I am generating reports from a DB. I have been able to successfully create a php page to show the results.
What I am looking to do know is to be able to automatically send my boss a copy of these reports daily.(I'm lazy)
I have been playing with sending an email using php. I've been successful doing this with static content.
I have not yet figured out how to send the email with the dynamic content.
Essentially what I am doing is running 10 queries against the DB(reports contain several ECHO statments) and I want to insert the results into the body of the email.
The report functions are like so:
function pull_QA($rpt_id,$number) {
$result=mysql_query("SELECT ans1,ans2,ans3,ans4,ans5 FROM rpt WHERE qid=$rpt_id;")
or die (mysql_error());
IF($data = mysql_fetch_array($result)){
echo(display_report($number,$data[ans1],$data[ans2],$data[ans3],$data[ans4],$data[ans5]));
}
}
function display_rpt($number,$a1,$a2,$a3,$a4,$a5)
{
echo "<tr><td><strong>Results were</strong</td></tr>";
echo"<tr><td>$a1</td></tr>";
echo"<tr><td>$a2</td></tr>";
echo"<tr><td>$a3</td></tr>";
echo"<tr><td>$a4</td></tr>";
echo"<tr><td>$a5</td></tr>";
echo "<tr><td> </td></tr>";
return;
What I have done so far is to run the queries like so:
$rpt_number = mysql_fetch_array($result);
$rpt1=display_rpt(1,1);
$header='Content-Type: text/html; charset=iso-8859-1';
$mail_to='$john@vis.com';
$mail_subject="weekly reports';
mail($mail_to,$mail_subject;$rp1,$header.)
What is happening is that the report is being pulled and echo'd to the screen rather than being inserted into the variable $rpt1. What can I do to make this do what I want it to do?
I had the idea to insert each row in the function into an array, but I was hoping there would be a more elegant way of doing this.
Bryan