Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 5th, 2011, 05:18 AM
Registered User
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control Email Sending

i have develop a website with email sending capabilty on the basis of one contact form it is sending the email but the information written in the text box is not being fetched out by it
Code:
      
        mailBody = mailBody.Replace("##Name##", Name.Text);
        mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
        mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
        mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
        mailBody = mailBody.Replace("##Comments##", Comments.Text);
it is not taking anything in Name.text which is a textbox.

Last edited by papimann; March 5th, 2011 at 05:20 AM..
Reply With Quote
  #2 (permalink)  
Old March 5th, 2011, 05:37 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

And how does your mail template look?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old March 5th, 2011, 05:40 AM
Registered User
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did not get you here is the full code
Code:
 string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
        string mailBody = File.ReadAllText(fileName);

        mailBody = mailBody.Replace("##Name##", Name.Text);
        mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
        mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
        mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
        mailBody = mailBody.Replace("##Comments##", Comments.Text);

        MailMessage mymessage = new MailMessage();
        mymessage.Subject = "Response from web site";
        mymessage.Body = mailBody;

        mymessage.From = new MailAddress("Kapilarora5988@gmail.com", "Sender Name");
        mymessage.To.Add(new MailAddress("papimann11@gmail.com", "Receivers Name"));

        SmtpClient mySmtpClient = new SmtpClient();
        mySmtpClient.Send(mymessage);
        mySmtpClient.EnableSsl = true;

        Message.Visible = true;
        FormTable.Visible = false;
Hi there,

A user has left the following feedback at the site:

Name: ##Name##
Email Address: ##Email##
Home Phone: ##HomePhone##
Business Phone: ##BusinessPhone##
Comments: ##Comments##
this is the template
Reply With Quote
  #4 (permalink)  
Old March 5th, 2011, 05:47 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Looks fine to me, so this should work. Maybe Name gets reset somewhere? Also, make sure that ##Name## etc is exactly the same in the template and in your code, including captilization and spaces.

If this doesn't help, you need to post more code and explain your situation in more detail.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; March 5th, 2011 at 05:56 AM..
Reply With Quote
  #5 (permalink)  
Old March 5th, 2011, 05:50 AM
Registered User
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am unable to fetch anything from the webpage i.e the contact form
as
Code:
 string s = Name.Text.ToString();
this also yields nothing s contains empty string and in the same manner the email which is being send out is like this
Code:
Hi there,

A user has left the following feedback at the site:

Name:
Email Address:
Home Phone:
Business Phone:
Comments:
and not as shown in the book
Reply With Quote
  #6 (permalink)  
Old March 5th, 2011, 05:56 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
If this doesn't help, you need to post more code and explain your situation in more detail.
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old March 5th, 2011, 06:03 AM
Registered User
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<table class="style1" runat="server" id="FormTable">
  <tr>
    <td align="center" colspan="3">
      <strong>Hello all You Can Contact Us From Here.......</strong></td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Name</td>
    <td align="left">
      <asp:TextBox ID="Name" runat="server"></asp:TextBox>
    </td>
    <td align="left">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="Name" CssClass="ErrorMessage" 
        ErrorMessage="Enter Your Name" Display="Dynamic">*</asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Email Address</td>
    <td align="left">
      <asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
    </td>
    <td align="left">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
        ControlToValidate="EmailAddress" ErrorMessage="Enter an Email Address" 
        CssClass="ErrorMessage" Display="Dynamic"></asp:RequiredFieldValidator>
      <br />
      <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="EmailAddress" ErrorMessage="Enter a Valid Email Address" 
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
        CssClass="ErrorMessage" Display="Dynamic"></asp:RegularExpressionValidator>
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Confirm Email Address</td>
    <td align="left">
      <asp:TextBox ID="ConfirmEmailAddress" runat="server"></asp:TextBox>
    </td>
    <td align="left">
      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
        ControlToValidate="ConfirmEmailAddress" ErrorMessage="Confirm Email Address" 
        CssClass="ErrorMessage" Display="Dynamic"></asp:RequiredFieldValidator>
      <br />
      <asp:CompareValidator ID="CompareValidator1" runat="server" 
        ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress" 
        ErrorMessage="Retype the Email Address" CssClass="ErrorMessage" 
        Display="Dynamic"></asp:CompareValidator>
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Home Phone Number</td>
    <td align="left">
      <asp:TextBox ID="PhoneHome" runat="server"></asp:TextBox>
    </td>
    <td align="left">
      <asp:CustomValidator ID="CustomValidator1" runat="server" 
        ClientValidationFunction="ValidatePhoneNumbers" CssClass="ErrorMessage" 
        Display="Dynamic" ErrorMessage="Enter Your Home or Business Phone Number" 
        onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Business Phone Number</td>
    <td align="left">
      <asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
    </td>
    <td align="left">
      &nbsp;</td>
  </tr>
  <tr>
    <td align="center" class="style2">
      Comments</td>
    <td align="left">
      <asp:TextBox ID="Comments" runat="server" TextMode="MultiLine"></asp:TextBox>
    </td>
    <td align="left">
      <asp:RequiredFieldValidator CssClass="ErrorMessage"  
        ID="RequiredFieldValidator4" runat="server" 
        ControlToValidate="Comments" ErrorMessage="Enter a Comment" 
        Display="Dynamic"></asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">
      &nbsp;</td>
    <td align="center">
      <asp:Button ID="SendButton" runat="server" Text="Send" 
        onclick="SendButton_Click" style="height: 26px" />
    </td>
    <td align="left">
      &nbsp;</td>
  </tr>
  <tr>
    <td align="center" class="style2" colspan="3">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
        CssClass="ErrorMessage" ShowMessageBox="True" ShowSummary="False" 
        HeaderText="Please Correct the following before going foreward" />
    </td>
  </tr>
</table>
this is the table used and i am not getting user response from this form
Reply With Quote
  #8 (permalink)  
Old March 5th, 2011, 06:17 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I am sorry, but I am not a mind reader, If you want help, you really need to provide better information. For example:

Where is this code used? In a page or in a User Control? Can you provide the code for both?
What happens when you debug the code? Do you see the controls and do they have a value?
When / how / where exactly do you execute the code that sends the e-mail?
And so on and so forth...

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; March 6th, 2011 at 07:08 AM..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Email Edward Colins BOOK: Beginning ASP.NET 4 : in C# and VB 9 September 19th, 2010 05:29 PM
Sending Mail from ContactForm User Control debscan ASP.NET 3.5 Basics 3 March 18th, 2010 01:35 AM
Sending an Email to the user causes the error - [SqlException (0x80131904) Paul Carter BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 19th, 2009 06:53 AM
Sending Email drjohnnygills BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 August 13th, 2009 05:09 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM



All times are GMT -4. The time now is 02:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.