954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Contact form

Hi, I'm trying to make a contact form, but it won't send the e-mail when I press send.
It doesn't make an error, just nothing happens.
I really don't know what the problem can be.
I'm doing it in .net c#

here is my code from my cs page:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class dkkontakt : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void submit_click(object sender, EventArgs e)
    {
        MailMessage Emailmsg = new MailMessage("noreply@hotmail.com", "mymail@hotmail.com");
        Emailmsg.Subject = "Kontaktform";
        Emailmsg.Body += "E-mail" + email.Text;
        Emailmsg.Body += "Navn: " + name.Text;
        Emailmsg.Body += "Tekst: " + besked.Text;
       
      

    }

}

Hope someone can see the problem and help me?

thanks

kischi
Junior Poster in Training
67 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Hi try this
string email = "Your@email.com";
MailMessage message = new MailMessage();
message.From = new MailAddress(email);
message.To.Add("recipient@email.com");
message.Subject = "Subject";
message.Body = "Body";
SmtpClient emailClient = new SmtpClient("SmtpServer");
emailClient.Send(message);

note that SmtpServer could be a real Smtp Server or 127.0.0.1 or "LocalHost"

hope that work

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

First try with your gmail id to send email. The below code will guide you how you can send email using your GMAIL ID. Modify your gmail credentials from the below code:

MailMessage mailMsg = new MailMessage();
// if you want to send HTML BODY then true for plain text body then false
mailMsg.IsBodyHtml = true;
mailMsg.Subject = "Asp.net articles";
mailMsg.Body = "<a href='http://shawpnendu.blogspot.com'>GO TO SHAWPNENDU'S BLOG</a>";
mailMsg.From = new MailAddress(shawpnendu@gmail.com);
mailMsg.To.Add(mxxion@yahoo.com);
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Credentials = new System.Net.NetworkCredential("shawpnendu@gmail.com", "password here");
// If you use your smtp server then try first with blocking the below line.
smtp.EnableSsl = true;
smtp.Send(mailMsg);


For further details you can read: http://shawpnendu.blogspot.com/2009/04/sending-web-email-in-aspnet-c.html

mail2saion
Posting Whiz in Training
247 posts since Apr 2009
Reputation Points: 26
Solved Threads: 44
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You