-1

table what i fetched from database

while($row2 = mysql_fetch_array($result2)) 
{
    $email_message .= '<tr>';
    $id= $row2['id'];
    $value= $row2['format( a.total_value, 2 )'];
    $email= $row2['email'];
    $email_message .='<td>'."$id".'</td>';
    $email_message .='<td>'."$value".'</td>';
    $email_message .='<td>'."$email".'</td>';
    $email_message .= '</tr>';
}                

i want to send email to xx@gmail.com(id=4) with first five row info and send email to ss@yy.com(id=13) with last row info.. After fetching above table from db how to do code for above using php. please help me out.

fantaghirocco
  • 4,761
  • 6
  • 38
  • 48

2 Answers2

0

You can use default mail() function. Find the example below.

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

Note: If you are using this on ur localhost, you need to check and change your smtp setting in php.in file. Mail function may/may-not work at all the time depending on your smtp settings.

user3227262
  • 563
  • 1
  • 6
  • 16
0

Please try something like that :

$clients = array();

while($row2 = mysql_fetch_array($result2)) 
{
    if (!array_key_exists($row2['email'], $clients)) {
        $clients[$row2['email']] = array($row2['format( a.total_value, 2 )']);
    }
    else {
        $clients[$row2['email']][] = $row2['format( a.total_value, 2 )'];
    }
}

foreach ($clients as $email => $values) {
    $email_message .= '<tr>';
    $id= $row2['id'];

    $email_message .='<td>'."$id".'</td>';

    foreach ($values as $value) {
        $email_message .='<td>'."$value".'</td>';
    }

    $email_message .='<td>'."$email".'</td>';
    $email_message .= '</tr>';
}
Simon Duflos
  • 133
  • 2
  • 12