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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.