PHP and Emails

I was wondering how I might go about creating an email script that gets the address off the contact form.

Something like:

mail("{$_POST['querytype']}",'FTN Query', $body, "From: {$_POST['email']}");

To generate the mailing function and then perhaps an option value for the email addresses to send the query to:

<option value="blahblah@blahblah.com">Legal Query</option>

and here’s where I get stuck…how do I get the “blahblah” part up to the mail to function?

Thhanks for any help

This is a html issue. Getting the blahblah@ part from the <option> is easy. The option is part of a select right? - So you get the option selected by refering to the select by name - as you would any other form element.

EG say your select is like this:
<select name=“myselect”>
<option>…
</select>

You access it like this: $_POST[‘myselect’];

I must highly recommend something to you though: DO NOT use a select box in the way you are intending - with REAL email addresses. It will be easily abused and probably get the site shut down. Any spammer who stumbles onto it will see that your script will email anyone by any email address provided in the form. They’ll then either save the page and edit it and send mail one by one manually or worse use a bot which will simply submit the form with its own values.

Instead, keep a list of email addresses in the script hard coded in an array and put their array index into the <option> value instead. When the form is submitted get the correct email address from the index and then email that address.

If you need further explanation of this then please say so.

thanks for the help…one thing though about the hardcoding…is this something i can do in a database as in just shove a bunch of email address into my mysql :slight_smile: database or should i just hard code the email address at the top of the script

thanks again

It doesn’t really matter. You can do either just as long as you’re not accepting the send-to address from a form which could be abused.

How you store the departments and their email addresses is down to you and whatever you find easiest or most efficient.

My comment was lost:(

What I would do is instead of having the legal dept’s e-mail as the value, set the value as law or something. Then do a switch statement to adjust the e-mail.

okay thanks all