Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET HTML
Hi guys
please help me I am failing to send an email in asp.net. my service provider does not allow the use of smtp, so i have to post my form to a page they gave me so that they can forward it to my email.
i have something like this:
 
<form method="post" action="http://their_page.com/mailto/mailto.pl">
<input type="hidden" name="followup-page" value="http://my_follo_page.com/mailto/confirm.html">
<input type="hidden" name="recip" value="email@domain.co.za">
<input type="hidden" name="subj" value="Feedback Form"> 
<input type="hidden" name="from" value="email@domain.co.za"> 
<input type="hidden" name="body"
 
How can i do this in ASP.net, i need this because my website is developed in ASP?
when i do it html, it works fine but doesnt work with an ASP.NET page (nothing happens when i click submit ) and i cannot use HTML because of the look, i cant use the ASP.NET master page with html page.
 

The other thing, how can i modify my register.asp page to send an confirmation email when somebody register? i only know how to send email with smtp, how can i post the username and email to that server page? this is my register.aspx.cs:
namespace WebApplication1.Account
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
           MembershipUser newUser = Membership.GetUser(RegisterUser.UserName);
            Guid newUserID = (Guid)newUser.ProviderUserKey;
            string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
            string verifyUrl = "VerifyNewUser.aspx?ID=" + newUserID.ToString();
            string fullPath = urlBase + verifyUrl;
            string appPath= Request.PhysicalApplicationPath;
           StreamReader sr = new StreamReader(appPath + "EmailTemplates/VerifyNewUser.txt");
           MailMessage message = new MailMessage();
            message.IsBodyHtml = true;
           message.From = new MailAddress("studentcompanionsa@gmail.com","Student Companion");
            message.To.Add( new MailAddress(RegisterUser.Email));
           message.CC.Add(new MailAddress("membership@studentcompanion.co.za"));
            message.Subject = "New User Registration";
            message.Body = sr.ReadToEnd();
            sr.Close();
            message.Body = message.Body.Replace("<%UserName%>", RegisterUser.UserName);
            message.Body = message.Body.Replace("<%VerificationUrl%>", fullPath);
            SmtpClient client = new SmtpClient();
           client.EnableSsl = true;
           client.Send(message);
            //FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);
            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                //continueUrl = "~/";
                continueUrl = "~/RegisterEmailNotification.aspx";
            }
            Response.Redirect(continueUrl);
            
        }
    }
}
 

 
THANK YOU VERY MUCH.
Posted 27-Apr-13 11:53am
katela708
Edited 27-Apr-13 16:10pm
v2
Comments
David_Wimbley at 27-Apr-13 21:16pm
   
Your question does not make sense. Can you be a little more clear. For clarification, is all you need to do the following in Asp.Net?
 
A form that submits the posts the values so you can then send those values via email to your inbox?
katela at 28-Apr-13 10:14am
   
my webhosting company will forward the form to my inbox email.
they dont allow smtp.
jkirkerx at 28-Apr-13 1:35am
   
Just use a html submit button instead of a asp.net object button
katela at 28-Apr-13 10:15am
   
a html submit button works when inside an html page, but it seems not to work when i put it inside an asp.net page
David_Wimbley at 28-Apr-13 13:14pm
   
Can you improve your question to include your whole code snippet because you keep saying it works inside an html page but not an asp.net page...HTML is HTML is HTML. You can't have a page without HTML it doesn't matter if you are doing webforms, mvc, coldfusion, php, perl...a form is a form is a form.
 
Can you provide a full code snippet of your issue, what you are saying doesn't make sense.
katela at 28-Apr-13 13:31pm
   
Ok when in my solution explorer i right click and add new "HTML page" and put this code it works:
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request for Assistance</title>
</head>
<body>
<div id="content">


Submit Email Request for Assistance


<form method="post" action="http://cgi-bin.myhost.co.za/mailto/mailto.pl">
<div>
Your name:
<input type="text" name="recip" />
</div>

<div>
Your email address:
<input type="text" name="from" />
</div>
<div style="width: 688px">
Subject:
<input type="text" name="subj" />
</div>

<div>
Details about your problem: <br />
<textarea name="body" cols="45" rows="4"></textarea>
</div>

<div>
<input type="submit" value="Submit" />
</div>
 


 
</form>
</div>
</body>
</html>
 

When i click submit, i receive that email. my webhosting company forward the email into my inbox.
 
But the problem is when i write the same code in an ASP.NET page (a page with aspx extention) inside two <html> tags, it doesnt work, the form doesnt do any thing.
The only reason i want to use ASPX page is because of my master page, i want this page to look also like other pages (menu, links,... because of master page)
 
Thank you
David_Wimbley at 28-Apr-13 13:49pm
   
This is a stupid question...you know your form is submitting to a perl script right? <form method="post" action="http://cgi-bin.myhost.co.za/mailto/mailto.pl">...That would probably be why it doesnt work.
katela at 28-Apr-13 13:54pm
   
I think that is why it doesnt work but i am not an expert.
Please assist on how i should do.
katela at 28-Apr-13 13:56pm
   
maybe that is why it doesnt work.
I am not an expert please assist.
Thanks
David_Wimbley at 28-Apr-13 15:25pm
   
Ok now im starting to understand...hooray.
 
So you have a form
 
<form method="POST" action="URL TO FILE THAT YOU ARE WORKING WITH">
 
method can be POST/GET. Right now you are looking for a Perl Script "http://cgi-bin.myhost.co.za/mailto/mailto.pl".
 
Assuming your host is the same thing you need to be referencing a link that looks like http://cgi-bin.myhost.co.za/SendMail.aspx.
 
Thats assuming that bit of code you posted that is C# is actually in a file called SendMail.aspx. So once you are posting your value to SendMail.aspx you can do whatever you need to do with those values there...whether it be save it to a file or database or whatever.
 
Honestly i've never heard of a host not allowing smtp...so to really solve this problem you should get a new hosting provider.
jkirkerx at 28-Apr-13 18:13pm
   
If I rememeber correctly, the asp.net button object and Imagebutton are buttons, but don't use the submit bahavior unless "Use Submit Bahavior" is selected, so they act like a HTML Submit Button.
 
The use if the Form Tag, in asp.net if different that html or php. In php for instance, you can have multiple form tags, with dedicated submit buttons inside, that will do different things, and carry the default behavior of being able to hit the enter key to submit a form.
 
Asp.Net doesn't do that, you can only have 1 form tag, and 1 submit behavior, and to program the enter key, you have to wrap that in a asp.net panel, and use the Default Button attribute.
 
I use asp.net buttons with handlers, that will fire a sub or function, in essence, posting back to the server the data within the form.
 
katela at 29-Apr-13 4:28am
   
Tanks, seem like this is the way to do it.
I'm not expert in C# especially with posting data to other forms. could u please give me a short example of a su or function that can collect data from my inputs and post it to another form?
thanks, i appreciate.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To help on the first question, I think it would go something like this.
 
It's been a long time since I've written a form to submit to another form, it was in PHP, but this is my version of how to do it in asp.net, and retain the enter key submission.
 
You may have to rename the ID's of the textbox and take out the prefix txt_, I forget what the name attribute is for.
 
I took advantage of 4.0 clientIDMode as set the controls as static to maintain the proper name and id values.
 
 
<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>]]>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

To help on the first question, I think it would go something like this.
 
It's been a long time since I've written a form to submit to another form, it was in PHP, but this is my version of how to do it in asp.net, and retain the enter key submission.
 
You may have to rename the ID's of the textbox and take out the prefix txt_, I forget what the name attribute is for.
 
I took advantage of 4.0 clientIDMode as set the controls as static to maintain the proper name and id values.
 
    <form id="form1" runat="server">
    <div>
        <asp:panel id="panel_emailSubmit" runat="server" style="width: 350px; text-align: left;" defaultbutton="bt_Submit" clientidmode="Static" xmlns:asp="#unknown">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 350px;">
                <tr>
                    <td style="width: 350px; height: 96px; text-align: left;">
                        <asp:textbox runat="server" id="txt_recip" clientidmode="Static">email@domain.co.za</asp:textbox>
 
                        <asp:textbox runat="server" id="txt_subj" clientidmode="Static">Feedback Form</asp:textbox>
 
                        <asp:textbox runat="server" id="txt_from" clientidmode="Static">email@domain.co.za</asp:textbox>
 
                        <asp:textbox runat="server" id="txt_body" clientidmode="Static"></asp:textbox>
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 350px; height: 46px; text-align: left;">
                        <asp:button runat="server" text="Button" id="bt_Submit" postbackurl="http://their_page.com/mailto/mailto.pl" clientidmode="Static" />
                    </td>                    
                </tr>
                <tr>
                    <td style="width: 350px; height: 0px; text-align: left;">
                        <input type="hidden" name="followup-page" value="http://my_follo_page.com/mailto/confirm.html" />
                    </td>
                </tr>
            </table>       
        </asp:panel>
    </div>
    </form>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 169
1 George Jonsson 145
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100