troubleshooting Question

Sending form email to recipient based on user choice.

Avatar of nedlogan
nedloganFlag for United Kingdom of Great Britain and Northern Ireland asked on
6 Comments1 Solution260 ViewsLast Modified:
Hi All,
I have a form that sends the results to my email address and works fine. However I want to send it to a different email address based on user selection.

On the form there is a list of radio buttons:

<p>My message is for:</p>
<asp:RadioButton ID="UserA" GroupName="Recipient" class="formfield"  runat="server" />User A<br />
<asp:RadioButton ID="UserB" GroupName="Recipient" class="formfield"  runat="server" />User B<br />

In the code behind I have the following:

if (IsPostBack)
            SmtpClient sc = new SmtpClient();
            StringBuilder sb = new StringBuilder();
            MailMessage msg = null;
            sb.Append("Email from: " + txtName.Text + "\n");
            sb.Append("Email: " + txtEmail.Text + "\n");
            sb.Append("Tel: " + txtPhone.Text + "\n");
            sb.Append("Question / Comments: " + txtQuestion.Text + "\n");
            msg = new MailMessage(txtEmail.Text, "", txtSubject.Text, sb.ToString());

            pnlForm.Visible = false;
            pnlConfirm.Visible = true;

At the moment the email goes to "". I presume I need to change that to the value from the RadioButton but also need to relate the value (UserA or UserB) to or

I'm going around in circles at the moment on what should be reasonably simple.
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros