/    Sign up×
Community /Pin to ProfileBookmark

Send form to different e-mails

On a website I’m making for my church I have a form that gives the user the ability to send a message to a different member of the staff, they do this by selecting the persons name in a drop down box. If you go [URL=”http://calvary.spencer-designs.com/contact/”]here[/URL] you can see the form. You’ll notice that the drop down box to select the staff member is disabled, but if you choose “Contact Staff Member” as the purpose the select box will be enabled. Now to do this I was told to use an array here is my code below…

[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]

But I was wondering if they do not select “Contact Staff Member” and say that they select “general information” how can I have that email to a different e-mail address? And same for if they select “website issue”

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@tgrk35Jun 18.2007 — Either use a switch or an if,then. I would use a switch, personally.

[CODE]switch ($_POST['radiobuttonname']){
case 'case1':
// Email whoever you want here
break;

case 'case2':
// Pull email address from the dropdown
break;
}[/CODE]


That should work.
Copy linkTweet thisAlerts:
@novemberGreyauthorJun 18.2007 — thanks for your help, could you show me better how to apply it to my current script, I'm very new to PHP...
Copy linkTweet thisAlerts:
@tgrk35Jun 18.2007 — No problem.

[code=php]<form method="post" action="">

<input type="radio" name="whatever" value="choice1" />
<input type="radio" name="whatever" value="choice2" />

<select name="person">
<option value="person1">Person1</option>
<option value="person2">Person2</option>
</select>

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

</form>

<?php

if($_POST['submit']){

switch ($_POST['whatever']){

// Email whoever you want to (not from dropdown)
case 'choice1':
$emails = array();
$emails = ('[email protected]','[email protected]');

mail(...);

break;

// Email whoever they selected in dropdown
case 'choice2':
$email = $_POST['person'];

mail(...);

break;
}

}[/code]


There you go.

Hope that helps.
Copy linkTweet thisAlerts:
@novemberGreyauthorJun 18.2007 — awesome, thankyou for your help!
×

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.9,
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,
)...