I have created a file called ‘userhistoryreport.php’. It will be setup to run once a day. The purpose of the file is to gather contact information and history for users who have interacted with the site for that particular day. The script works, but I am unsure of how to get the results to send to email. The email should be formatted just like the page in the broswer – where each user is listed with their history. Any help is appreciated.
echo '<div style="padding: 0 20px;">';
echo '<span style="display: block; font-size: 22px; font-weight: bold; margin: 25px 0 -15px 0;"> User Activity on' . $website . 'for' . $date . '</span>';
//query the database for today's history
$result = mysql_query("SELECT * FROM user_history WHERE date = '$date' ORDER by name, time, title")
or die(mysql_error());
$old_user = '';
while($row = mysql_fetch_array( $result )) {
$new_user = $row['uid'];
if ($new_user != $old_user) {
echo '<br /><br /><hr />' . '<span style="font-size: 18px; font-weight: bold;">' . $row['name'] . '</span>' . '<br />' . $row['company'] . '<br />' . $row['email'] . '<br />' . $row['phone'] . '<br /><br />';
$old_user = $new_user;
}
echo '<ul><li>' . $row['time'] .
'<ul><li>' . $row['title'] . ' (<a href="' . $row['url'] . '">' . $row['url'] . '</a> )' . '</li></ul>' . '<br /><br />' .
'</li></ul>';
}
echo '</div>';
echo
'<div style="position: fixed; bottom: 0; height: 40px; width: 100%; margin: 20px 0 0 0; background: #000; color: #FFF; line-height: 40px;">' .
'Report generated ' . $date . ' ' . $time .
'</div>';
Straight from the mail() function in the php manual, try this;
Put all of your html into a string instead of echoing it immediately, by replacing all your echoes with something like this;
To display the report, use
To mail the report, put this bit after the final closing tag to send the report with html.