Jump to content

E-mailing the result of a Query.


Person

Recommended Posts

Ok, so the Query part works, now i just need to E-mail the result in an E-mail form to someone. Could some help me out with the code.

 

<?php
$host = "localhost";
$user = "user_user";
$pass = "password";
$dbname = "user_user";

$con = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "SELECT SUM(1) AS clicks, SUM(`clcpc`), SUM(`chcpc`) FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND  `date` = '20070418'";
echo $query;

$result= mysql_query($query);
$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "Clicks:  " . $row['user_id'];
}

?>

<?php 
$email_to = "[email protected]";
$email_from = "server do not reply";
$email_title = "Total Clicks report";
$email_body ="Dear " . $user;

$result= mysql_query($query);

Thank you,
support Site;
   $success = mail($to,$from,$title,$body,
              "From:$from\r\nReply-To:server do not reply");

?>

Link to comment
https://forums.phpfreaks.com/topic/49806-e-mailing-the-result-of-a-query/
Share on other sites

<?php
$host = "localhost";
$user = "user_user";
$pass = "password";
$dbname = "user_user";

$con = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "SELECT SUM(1) AS clicks, SUM(`clcpc`), SUM(`chcpc`) FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND  `date` = '20070418'";
echo $query;

$result= mysql_query($query);
$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
  $clicks .= "Clicks:  " . $row['user_id'];
}

$email_to = "[email protected]";
$email_from = "server do not reply";
$email_title = "Total Clicks report";
$email_body ="Dear $user,\n\nHere is that list of Clicks\n\n$clicks\n\nThank you,\nsupport Site;";

$success = mail($to,$from,$title,$body,"From:$from\r\nReply-To:server do not reply");

?>

<?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.