Jump to content

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: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\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>

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.