/    Sign up×
Community /Pin to ProfileBookmark

Contact Form – Change Receiver

On my contact form I want to allow the user to pick who they want the email to go to. So I’m going to have a drop-down list where they can select the person. How would I do this? Or would this be done with PHP?

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@ricpApr 04.2007 — Thanks for the most minimal amount of information possible. A few questions..

1) How many email addresses are there?

2) How do you wish to send the email (smtp server side or via the client side default email application)?

3) Do you need to cater for those who have js disabled.
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — Sorry for the lack of information. There will probably be around 10 different emails to choose from. I would like to send the form server side via PHP. And yes I would like the form to be accessible to those with js diabled.
Copy linkTweet thisAlerts:
@ricpApr 04.2007 — Ok, if you need this to be non-js supportable then we would need to move just about all the processing onto the server side. The process I would go with is this one..

1) While parsing/generating the page on the server side, include the emails using php, so you have something like..

[code=html]
<form method="post" action="emailForm.php">
<select name="email">
<? populateEmailAddresses() ?>
</select>
<input type="submit" value="Email"/>
:
// include any further form elements
:
</form>
[/code]


inside the populateEmailAddresses() function in the php is code to output the addresses in the format like so..

[code=html]
<option value="[email protected]"> foo </option>
[/code]


The page is then all sent to the client with a form which will pass the selected email address to the page emailForm.php

2) Inside emailForm.php you have the php code for manipulating the POST values sent and initialising the message to be sent through SMTP, then sending it.



Basically there is no JS in there, even the form submission is handled "naturally" on the client to avoid the need for JS. You could overload the form using JS and have xmlhttp send the value of the selected email to a server side script that would send what it needs to. That would at least allow those with script enabled to avoid submitting/reloading the page.

Hope that helps.
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — awesome thanks for your help!
Copy linkTweet thisAlerts:
@pcthugApr 04.2007 — You could have a select field like so:
[code=html]
<select name="to">
<option value="0">John</option>
<option value="1">Jill</option>
<option value="2">Bill</option>
</select>
[/code]


[code=php]
$emails = array(
'[email protected]',
'[email protected]',
'[email protected]');

$email = isset($_POST['to']) && array_key_exists($_POST['to'], $emails) ? $emails[$_POST['to']] : $_POST[0];
[/code]
Copy linkTweet thisAlerts:
@TaschenApr 04.2007 — 
[code=html]
<option value="[email protected]"> foo </option>
[/code]

[/QUOTE]

I would strongly advise you not to follow the above method. Where possible never publish an email address directly to your website in plain text, it aids spam harvesters.

Rather make your value a resource identifier of the form 'n'
[code=html]
<option value="n1"> foo </option>
[/code]

Use this to access an array of email address in your php script
[code=php]$available_mail_addresses = array("n1"=>"[email protected]", "n2" => "[email protected]");[/code]
Hard coding email addresse into you mail processing script will also make it harder for your form processor to be abused by third parties.

And I see that while I was writing that PC Thug replyed on similar lines.
Copy linkTweet thisAlerts:
@ricpApr 04.2007 —  Where possible never publish an email address directly to your website in plain text, it aids spam harvesters.[/QUOTE]
It's a fair point, I had overlooked that when I was doing the generalisation, but it's definitely valid.

That said, is there such a thing as a spam free email address?

?
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — thankyou everyone for your help!
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — Taschen and PC thug, using your method, could one of you show me an example of how the mailing script should look?
Copy linkTweet thisAlerts:
@pcthugApr 04.2007 — [code=php]
$emails = array(
'[email protected]',
'[email protected]',
'[email protected]');

$email = isset($_POST['to']) && array_key_exists($_POST['to'], $emails) ? $emails[$_POST['to']] : $_POST[0];
$subject = 'Foo';
$message = 'Bar';

mail($email, $subject, $message);
[/code]
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — Thanks for your help PCthug!
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — I uploaded my form and my PHP script to one server, and it wouldn't work for some reason. When I would click Submit it would give me a "couldn't find page error" and the address of the PHP script would be in the address bar. So then I uploaded my files in a different server and it worked perfectly. What do you think is the problem with the first server?
Copy linkTweet thisAlerts:
@novemberGreyauthorApr 04.2007 — I figured it out, I ran a test php script, It seems my church doesn't have PHP installed on their server, lol.
×

Success!

Help @novemberGrey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...