Hi All,

I have an internal work order page and I am 'trying' to get the CC contacts to be emailed with a foreach but I also want to add the person ordering the work to the array. But the way I would do it with a known amount of IDs would be like this...

$directorid = $_POST['Director']; //the person ordering the work

$_POST['Contacts'] = array();// Make it an array

foreach ($_POST['Contacts'] as $contact) { //Set the elements in the array
	$Contacts0= $contact[0];
	$Contacts1 = $contact[1];
	$Contacts2 = $contact[2];
	$Contacts3 = $contact[3];
   	 }
}

But that will only work if I know how many names will be selected. In this case it may be 0 or up to 6. How would I do that?

And also, I want to 'add' the director id to the list, how can I also do that?

I know it can be done, just lost on where to go from here.

As always, thanks a bunch.

Don

    Well, your description does not jibe with the code sample (at least in my brain), and the code is not going to work anyway since the $_POST['contacts'] = array(); is going to create an empty array.

    What exactly are you starting with? Is $_POST['contacts'] an array?

    What do you want to end up with? A semicolon-separated list of email addresses to use in the "Cc:" header of a mail() command?

      Hi ND,

      Yea, I slapped that together trying to show what I want. I will elaborate.

      I have a function to make the cc checkboxes.

      function makeCheckboxList($name,$list,$selected="") {
        global $x;
          while(list($value,$label) = each($list)) {
      	if($value['enabled']=='1') {
       $options .= '<input name="'.$name.'" type="checkbox" value="'.$value.'" tabindex="'.$x.'" checked="checked" />&nbsp;'.$label.'<br />';
      } else {
       $options .= '<input name="'.$name.'" type="checkbox" value="'.$value.'" tabindex="'.$x.'" />&nbsp;'.$label.'<br />';
      }
       }
       return $options;
      }
      

      And then I define it in my form.

        $x='2'; //tabindex value
      $list2 = makeCheckboxList('Contacts[]',$contactname2,$contactname2);
      echo $list2;
      

      And I have a drop down for the Director (person ordering the job) and I want to include this id for my email array (added to the Contacts array above).

      function makeDropList($name,$list,$selected="") {
        // $name       select name
        // $list       array of value, label pair
        // $selected   selected value
        global $x;
        while(list($value,$label) = each($list)) {
          $options .= '<option value="'.$value.'">'.$label.'</option>';
        }
        $dropList = '<select name="'.$name.'" tabindex="'.$x.'">'.$options.'</select>'."\n";
        if($contactname == " ") {
        $dropList = ereg_replace("value=\"$selected\"","value=\"$selected\" selected",$dropList);
        }
        return $dropList;
      } 
      
      $x='1'; //tabindex value
      $list = makeDropList('Director',$contactname,$contactname);
      echo $list;
      

      Then in my form, I was going to do foreach loop and go thru the names and send an email to each.

      //Open SMTP port to send emails
      $fp = fsockopen(localhost, 25, $errno, $errstr, 30);
      
      foreach ($_POST['Contacts'] as $contact) {
      		$EmailAddress = $row['ea'];
      		$FirstName = $row['fn'];
      		$LastName = $row['ln'];
      		echo '-->'.$FirstName.' '.$LastName.' '.'at '.$EmailAddress.'<br><br>';
      		//Send email to them
      			$message = '<html><head></head><body><font size="2" face="Arial, Helvetica, sans-serif">This is to notify you that Job Order #'.$ID.' has been added/updated. Please check the status <a href="http://www.advisoryzone.org/staff/editjoborder.php?id='.$ID.'">here.</a></font></body></html>';
      
      		$header = 'MIME-Version: 1.0' . "\r\n";
      		$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      		$header .= "From: example@example.com\r\n";
      		$subject = 'Job Order Notification - '.$displaydate;
      		$email_to = $EmailAddress;
      		mail($email_to, $subject ,$message ,$header) ;
      	}
      	fclose($fp); // close ftp port
      

      This code will not work, but should help make it a little clearer where I am heading with this. Does that make a little more sense?

      I am TOTALLY open to suggestions here, since 'I am but the student and you are the master', to use a known quote. 🙂

      Thanks for the help,

      Don

        OK, so if $POST['Contacts'] is an array, and you have the director as a scalar value in $POST['Director'], all you need to do is:

        $_POST['Contacts'][] = $_POST['Director'];
        

          Thanks NogDog, it worked perfectly.

          Owe ya one!

          Don

            Write a Reply...