Jump to content

Recommended Posts

Then I use the while look in my code no emails are sent, but when I take it out only one is sent.

Are there any other ways that I loop through the recordset to send email to everyone.

Please help

 

Here's the code:

 

elseif ( $to == "Buyers") {

mysql_select_db($database_prop, $prop);

$query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'");

 

$dist = mysql_query($query_dist, $prop) or die(mysql_error());

$row_dist = mysql_fetch_assoc($dist);

$totalRows_dist = mysql_num_rows($dist);

 

 

// ---------------- SEND MAIL FORM ----------------

 

 

if($totalRows_dist > 0)

{

$count = 0;

while ($rows_dist = mysql_fetch_assoc($dist))

{

echo $row_dist['email'];

// send e-mail to ...

$to2 = $row_dist['email'] . ', ';

 

echo $to2;

 

// Your subject

$subject="Property Distribution";

 

// From

$header="from: Property Networking Solutions";

 

// Your message

$messages= "Match alert notification\t\n\t\nThis property was sent to you by Property Networking Solutions.\t\n\t\nProperty Description:\t\nType: $proptype\t\nProvince: $propprov\t\nCity: $propcit\t\nSuburb: $propsub\t\nPrice: R $propprice\t\n\t\nHere is a link to the property: http://www.propertyforsalesa.co.za/buyer_detail_view.php?id=$propid\t\n\t\n\t\n" ;

 

// send email

$sentmail = mail($to2,$subject,$messages,$header);

$count++;

}

 

}

 

}

 

Link to comment
https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/
Share on other sites

have a look at the changes bellow and try it;

 

elseif($to == "Buyers") {
   mysql_select_db($database_prop, $prop);
   $query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'");

   $dist = mysql_query($query_dist, $prop) or die(mysql_error());
   $totalRows_dist = mysql_num_rows($dist);

   if($totalRows_dist > 0)
   {
      while($rows_dist = mysql_fetch_assoc($dist))
      {
         echo $row_dist['email'];
         // send e-mail to ...
         $to2 = $row_dist['email'];

         echo $to2;

         // Your subject
         $subject="Property Distribution";

         // From
         $header="from: Property Networking Solutions";

         // Your message
         $messages= "Match alert notification	 	 This property was sent to you by Property Networking Solutions.	 	 Property Description:	 Type: $proptype	 Province: $propprov	 City: $propcit	 Suburb: $propsub	 Price: R $propprice	 	 Here is a link to the property: http://www.propertyforsalesa.co.za/buyer_detail_view.php?id=$propid	 	 	 " ;

         // send email
         if(mail($to2,$subject,$messages,$header))
         {
            echo 'mail sent to '.$to2;
         }
         else
         {
            echo 'mail not sent to '.$to2;
         }
      }
   }
}

I put the while in bold.

 

 

 

Here's the code:

<?php>

elseif ( $to == "Buyers") {

mysql_select_db($database_prop, $prop);

$query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'");

 

$dist = mysql_query($query_dist, $prop) or die(mysql_error());

$row_dist = mysql_fetch_assoc($dist);

$totalRows_dist = mysql_num_rows($dist);

 

 

// ---------------- SEND MAIL FORM ----------------

 

 

if($totalRows_dist > 0)

{

$count = 0;

while ($rows_dist = mysql_fetch_assoc($dist))

{

echo $row_dist['email'];

// send e-mail to ...

$to2 = $row_dist['email'] . ', ';

 

echo $to2;

 

// Your subject

$subject="Property Distribution";

 

// From

$header="from: Property Networking Solutions";

 

// Your message

$messages= "Match alert notification\t\n\t\nThis property was sent to you by Property Networking Solutions.\t\n\t\nProperty Description:\t\nType: $proptype\t\nProvince: $propprov\t\nCity: $propcit\t\nSuburb: $propsub\t\nPrice: R $propprice\t\n\t\nHere is a link to the property: http://page.php?id=$propid\t\n\t\n\t\n" ;

 

// send email

$sentmail = mail($to2,$subject,$messages,$header);

$count++;

}

 

}

 

}

<?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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