How to send to multiple users at once

Hi all. I am trying to send mail to multiple users at once. i am having problem with it. when i use a single user, it delivers.
thanks
code below:

[code]

//with username it works as expected

$_GET['id'] = 'user[member=73586]User[/member].com';
$i = 1;

$bill_status = "SCHEDULED";

$query = "SELECT username, trans_ref, due_date, service_provider,

    service_type, amount_paid, bill_status, recurring

    FROM acc_bills

    JOIN acc_login_details ON acc_bills.user_id = acc_login_details.user_id

    WHERE acc_login_details.username = '$_GET[id]'

    AND acc_bills.bill_status = :bill_status";

$stmt = $pdo->prepare($query);

$stmt->bindValue(':bill_status', $bill_status, PDO::PARAM_STR);

$stmt->execute();

$message1= "

Up-Coming Bills
#Trans Ref
Due Date
Service Provider
Service Type
Amount Paid
Recurring
";

while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){

$users = $rows['username'];

$message1 .= " ";

$message1 .= " " .$i++."";

$message1 .= " ".$rows['trans_ref']."";

$message1 .= " ".$rows['due_date']."";

$message1 .= " ".ucwords($rows['service_provider'])."";

$message1 .= " ".ucwords($rows['service_type'])."";

$message1 .= " ".number_format($rows['amount_paid'],2)."";

$message1 .= " ".$rows['recurring']."";

$message1 .= " ";

}

$message1 .= "";

##-------------------------##

## OVERDUE BILL REMINDER ##

##-------------------------##

$j = 1;

$bill_status = "OVERDUE";

$query = "SELECT username, trans_ref, due_date, service_provider,

            service_type, amount_paid, bill_status, recurring,

            DATEDIFF(NOW(), due_date) AS days_diff

    FROM acc_bills

    JOIN acc_login_details ON acc_bills.user_id = acc_login_details.user_id

    WHERE acc_login_details.username = '$_GET[id]'

    AND acc_bills.bill_status = :bill_status";

$st = $pdo->prepare($query);

$st->bindValue(':bill_status', $bill_status, PDO::PARAM_STR);

$st->execute();

$message2 = "

Overdue Bills

#

Trans Ref

Due Date

Days Overdue

Service Provider

Service Type

Amount Paid

Bill Status

Recurring

";

while($rows = $st->fetch(PDO::FETCH_ASSOC)){

$users = $rows['username'];

$message2 .= " ";

$message2 .= " " .$j++."";

$message2 .= " ".$rows['trans_ref']."";

$message2 .= " ".$rows['due_date']."";

$message2 .= " ".$rows['days_diff']."";

$message2 .= " ".ucwords($rows['service_provider'])."";

$message2 .= " ".ucwords($rows['service_type'])."";

$message2 .= " ".number_format($rows['amount_paid'],2)."";

$message2 .= " ".$rows['bill_status']."";

$message2 .= " ".$rows['recurring']."";

$message2 .= " ";

}

$message2 .= " ";

##-------------------##

## BILL PAYMENT PLAN ##

##-------------------##

$message3 = "Amount Needed To Pay Up-Coming Bills Due Date Amount Due";

$query = " SELECT username, due_date,

        SUM(amount_paid) as total_amt

        FROM acc_bills

        JOIN acc_login_details ON acc_bills.user_id = acc_login_details.user_id

        WHERE acc_login_details.username = '$_GET[id]'

        Group By MONTH(due_date), DAY(due_date)

        ORDER BY due_date ASC";

$stmt = $pdo->prepare($query);

$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

$message3 .= " ";

$message3 .= " ".$row['due_date']."";

$message3 .= " ".$row['total_amt']."";

$message3 .= " ";

}

$message3 .= " ";

$footer = "

This email was intended for {$users}";

$msg = $message1 . $message2 . $message3 . $footer;

//Debug lines

echo "Creating email for user '{$users}'

\n";

echo "Message:'

{$msg}

\n";

[/code]

Comments

  • Code you showed has nothing to do with sending emails.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion