Jump to content

PHP Contact form with options


willem_e7

Recommended Posts

Hello all. I have a simple PHP contact form that I've been using for a while. I would like to know if it's possible to have check box options in my HTML page when using the form that would allow users to select which person to contact.

 

So basically, based on the check box option, the php form would submit the information to a variation of 5 email addresses.

 

Is this possible? Thanks if anyone can steer me in the right direction!

Link to comment
https://forums.phpfreaks.com/topic/196991-php-contact-form-with-options/
Share on other sites

Sure it's possible.

 

Give each separate checkbox it's own unique name, such as checkbox name=admin [email protected]

 

Checkboxes only pass information when they're checked, so you can do a simple check on the processing page:

 

if (isset(_$POST['admin']))
  {
$to=$_POST['admin']
  }

Or, if you have multiple, use case/switch.

Yes.  If  you want to hard-code the email addresses into the php you can just:

<input type=checkbox name=email[] value="[email protected]">[email protected]<br>
<input type=checkbox name=email[] value="[email protected]">[email protected]<br>

 

Then the php side would be:

 

$fromEmail="[email protected]";
$toDefault="[email protected]";
$emails=$_POST['email'];
$header="From: $fromEmail \r\n";
foreach ($emails as $email){
$header=$header."CC: $email";
if (!($email==$emails.end))
$header=$header . " \r\n";
}
mail($toDefault, $subject, $message, $header);

 

Note: I didn't define $subject or $message so this won't work until you morph it into your needs.

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.