How to send e-mail to multiple recipients from database individually

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • franda
    New Member
    • Sep 2014
    • 6

    How to send e-mail to multiple recipients from database individually

    hi i'm currently sending multi email recipients in one go is it possible to send it individually? please help thank you.

    Code:
    <?php
    require_once 'library/config.php';
    ?>
    						
     <?php
    
      $qe = "SELECT `cust_id`, `cust_name`, `cust_email`, `cust_phone`, `cust_address`, `cust_city`, `cust_state`, `cust_country`, `cust_pin`, `cust_spec_note` FROM `sland_pizza_customer` WHERE 1";
      $re = dbQuery($qe);
      if(dbNumRows($re)>0)
      {
      while($ra = dbFetchAssoc($re)):
      $cust_email .=$ra['cust_email'].","." ";
      endwhile; 
      }
      
    
       
    $to  = $cust_email; // sender
    $subject = 'Get 5% Discount Every Order';
    
    // 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";
    $headers .= 'From: yoursite Penrith<newsletter@yoursite.com.au>' . "\r\n";
    
    // Put your HTML here
    $message = file_get_contents('marketing.html');
    
    // Mail it
    mail($to, $subject, $message, $headers);
    echo "It's Sent";
    ?>
    Last edited by Rabbit; Sep 25 '14, 06:56 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Instead of appending all the email addresses together, move the mail stuff into your loop.

    Comment

    • franda
      New Member
      • Sep 2014
      • 6

      #3
      hi Rabbit thanks for help but that did not fix my problem its still showing all the email recipients that the emails where sent to, i want every customer to see only they email when they open the email

      example: From: newsletter@your site.com and To: customer@whatev er.com


      instate of From: newsletter@your site.com
      To: customer@whatev er.com, customer2@whate ver.com, customer3@whate ver.com, customer4@whate ver.com.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Please show the new code.

        Comment

        • franda
          New Member
          • Sep 2014
          • 6

          #5
          its same as the above code, it does not sends them one by one! it sends them all together, i want to send them one by one. thanks Rabbit

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            You said "that did not fix my problems". The implication is that you made the code changes I suggested. But then you said there is no new code. Which means you didn't make the code changes I suggested.

            You need to make the changes I suggested in my first post then post the new code if you are still having issues.
            Last edited by Rabbit; Sep 26 '14, 07:35 PM.

            Comment

            • franda
              New Member
              • Sep 2014
              • 6

              #7
              here is the updated code, it says "It's Sent" but i dont see any emails coming thank you Rabbit

              Code:
              <?php
              require_once 'library/config.php';
              
              
               $qe = "SELECT `cust_id`, `cust_name`, `cust_email`, `cust_phone`, `cust_address`, `cust_city`, `cust_state`, `cust_country`, `cust_pin`, `cust_spec_note` FROM `sland_pizza_customer` WHERE 1";
                $re = dbQuery($qe);
                if(dbNumRows($re)>0)
                {
              
              
                 $num=dbNumRows($re);
              
              
                  while ($i < $num)
              
              {
              
                  $cust_name='$row[cust_name]';
              
                  if($qe == TRUE)
              
              {
              
               
              $to  ='$row[cust_email]'; // sender
              $subject = 'Get 5% Discount Every Order';
               
              // 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";
              $headers .= 'From: yoursite Penrith<newsletter@yoursite.com.au>' . "\r\n";
               
              // Put your HTML here
              $message = file_get_contents('marketing.html');
               
              // Mail it
              mail($to, $subject, $message, $headers);
              echo "It's Sent";
              
              
              $i++;
              
              }
              
              }
              }
              
              ?>

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Why did you change your loop condition?

                Comment

                • franda
                  New Member
                  • Sep 2014
                  • 6

                  #9
                  what you suggest me to do, can you give me some code that i can just copy and paste thank you Rabbit

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    This isn't a code writing service, we are here to help you learn what you did wrong so you can learn to be self sufficient.

                    What I am suggesting you do is to change your loop condition back to what it was. The only changes I suggested was to stop appending the addresses and to move the code around. You made way more changes than I suggested. Start with your original code again and only make the changes I originally suggested.

                    Comment

                    • franda
                      New Member
                      • Sep 2014
                      • 6

                      #11
                      looks like i did waste my time, im just gonna keep trying till i get it done. thanks anyway

                      Comment

                      Working...