Jump to content

Recommended Posts

Hi Guys,

 

im trying to figure out the best way to do the mass email part of my code, i have put a while loop in but not sure if thats best:

 

<?php
  case "mass-email":
  
    // How many emails
    $q_num = "SELECT * FROM `fcp_customers`";
    $r_num = mysql_query($q_num);
    $n_num = mysql_num_rows($r_num);
  
    print("<form action=\"admin.php?page=mass-email\" method=\"POST\">");
  
    // Mass e-mails form
    print("<table width='80%' border='0' cellpadding='5' cellspacing='1' />\n");
    print("<tr>\n");
    print("<th colspan='2'>Mass E-Mail Customers</th>\n");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td class='td_style' align='left' valign='top'>E-Mail:</td><td class='td_style' align='left'><select name=\"cus_emails\"><option value=\"email_all\">--> MASS EMAIL ALL CUSTOMERS! - ($n_num) <--</option>");
    
    $q_emails = "SELECT * FROM `fcp_customers`";
    $r_emails = mysql_query($q_emails);
    
    // Loop
    while ($a_emails = mysql_fetch_array($r_emails))
    {
     // Customers email
     $emails = $a_emails['email'];
     
     // Print
     print("<option value=\"$emails\">$emails</option>");
    }
    
    print("</select></td>\n");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td class=\"td_style\" align='left' valign=\"top\">E-Mail Subject:</td><td class='td_style' align='left'><input type=\"text\" name=\"cus_subject\" size=\"70\"></td>");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td class=\"td_style\" align='left' valign=\"top\">E-Mail Message:</td><td class='td_style' align='left'><textarea name=\"cus_message\" rows=\"20\" cols=\"70\"></textarea></td>");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td colspan='2' class='td_style' align='right'><input type='submit' name='submit_emails' class=\"btn_style\" value='Send!'></td>\n");
    print("</tr>\n");    
    print("</table>");
    
    print("</form>");
    
    // Deal with the submission
    if (isset($_POST['submit_emails']))
    {
      // Post vars
      $c_e = $_POST['cus_emails'];
      $c_s = $_POST['cus_subject']; 
      $c_m = $_POST['cus_message']; 
      
      // Mass or single email
      if ($c_e == 'email_all')
      {
        // Mass email
        
        while ()
        {
        
        }
   
        } else {   
         
        // Single email
       
        $to = $c_e;
        $subject = $c_s;
        $from = "info@firstchoicepharmacy.co.uk";
      $body = "<h3>Newsletter from firstchoicepharmacy.co.uk</h3>";
        $body .="<br /><br />";
        $body .="$c_m<br /><br />";
        $body .="Regards <br /><a href=\"http://www.firstchoicepharmacy.co.uk\">http://www.firstchoicepharmacy.co.uk</a>";
        $headers = "MIME-Version: 1.0\r\n";  
        $headers = "From: firstchoicepharmacy.co.uk<$from>\n"; 
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";  
     
        $mail = mail($to,$subject,$body,$headers);
      
        // Success
        if ($mail)
        {
          print("<br /><span class=\"mail_ok\"><img src=\"images/tick.png\"> You have successfully emailed [<b>$to</b>]</span><br /><br /><br />");
        }
       
      }
    
    }
  
  break;
?>

 

not sure what to do with the while loop exactly lol

 

any help would be great

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/116782-mass-emailing/
Share on other sites

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.