Jump to content

match two arrays then send the key value as a email (help


redarrow

Recommended Posts

This code allow a user to use a drop box and select a name then

 

the code compares two arrays and then if a match sends a email to the user

via the named array key.

 

any body do it in a shorter way cheers.

 



<html>

<title></title>

<?php

if($_POST['submit']){
    
     $switch_array=array("john"=>"john@hwat_ever.com",
     "bob"=>"bob@what_ever.com","petter"=>"petter@what_ever.com",
     "paul"=>"paul@what_ever.com","kevin"=>"kevin@what_ever.com",
     "chris"=>"chris@what_ever.com","tom"=>"tom@what_ever.com");  
         
      foreach($switch_array as $key=>$posted_match){   
         
         if($_POST['posted_people']=="$key"){
        
       $to      = ".$posted_match.";
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)){
    
    echo "A email was sent to ".$posted_match."";
    
    break;

}else{
    
echo("Sorry no email sent out");
    
    break;
    
    }    
        break;
    }
}
}
?>

<?php $people_array=array("john","bob","petter","paul","kevin","chris","tom");?>

<center>

<form method="POST" action="">
<select name="posted_people">
<?php foreach($people_array as $people){
    echo"<option value='$people'>$people</option>";}
     ?>
</select>

<br /><br />

<input type="submit" name="submit" value="submit">

</form>

</center>

</html>

Archived

This topic is now archived and is closed to further replies.

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