Estou a fazer uma aplicação em que quando clicar num botão tenho de enviar um email.
Tenho la minha página uma input type=Text
e um button type="button"
que com css ficou assim ->
.
Eu preciso que quando carregar nessa seta, seja enviado um email como está no código, e no corpo de email seja enviado também o que está na input text. Se o input text estiver vazia, deve dar erro e não fazer nada.
Eu clico no botão mas não faz nada. O que pode está acontecendo de errado?
Código que tenho para já:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Cegos Analytics | Lockscreen</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition lockscreen">
<!-- Automatic element centering -->
<div class="lockscreen-wrapper">
<div class="lockscreen-logo">
<img src="/Images/^082594892CD6A1E2D2CF4B7361463D84FEF2B4C6FEBD2707B5^pimgpsh_fullsize_distr.png" alt="Cegos Logo">
</div>
<br />
<!-- User name -->
<div class="lockscreen-name"></div>
<!-- START LOCK SCREEN ITEM -->
<div class="lockscreen-item">
<!-- lockscreen image -->
<div class="lockscreen-image">
<img src="/Images/locked.jpg" alt="Locked Screen">
</div>
<!-- /.lockscreen-image -->
<!-- START LOCK SCREEN ITEM -->
<div class="lockscreen-item">
<!-- lockscreen image -->
<div class="lockscreen-image">
<img src="/Images/locked.jpg" alt="Locked Screen">
</div>
<!-- /.lockscreen-image -->
</div>
<!-- lockscreen credentials (contains the form) -->
<form class="lockscreen-credentials">
<div class="input-group">
<input type="Text" class="form-control" placeholder="Username">
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script runat="server">
public void SendEmail()
{
try
{
SmtpClient cliente = new SmtpClient();
cliente.Host = "smtp.sapo.pt";
cliente.EnableSsl = true;
cliente.Credentials = new NetworkCredential("[email protected]", "cegoc123456");
MailMessage mensagem = new MailMessage();
mensagem.Sender = new MailAddress("[email protected]");
mensagem.From = new MailAddress("[email protected]");
mensagem.To.Add(new MailAddress("[email protected]"));
mensagem.Subject = "Pedido de suporte Plataforma Cegos Analytics";
mensagem.Body = "Recebeu um pedido de suporte da Plataforma Cegos Analytics para recuperação de password referente ao utilizador:";
mensagem.IsBodyHtml = false;
mensagem.Priority = MailPriority.High;
cliente.Send(mensagem);
}
catch (Exception ex)
{
Response.Write("******EMAIL FAILED. PLEASE CONTACT YOUR ADMINISTRATOR**** See log file in C:\\Logs");
CreateLogFiles(ex.Message);
ErrorLog("C:\\Logs\\log.txt", ex.Message);
Response.Write(ex.Message);
}
}
</script>
<div class="input-group-btn">
<button type="button" class="btn" onclick="SendEmail()" runat="server"><i class="fa fa-arrow-right text-muted"></i></button>
</div>
</div>
</form>
<!-- /.lockscreen credentials -->
</div>
<!-- /.lockscreen-item -->
<div class="help-block text-center">
Enter your username to retrieve your session
</div>
<div class="text-center">
<a href="../Default.aspx">Or sign in as a different user</a>
O que eu tenho essencialmente é uma pa´gina recoverpassword.aspx onde tenho isso:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Cegos Analytics | Lockscreen</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition lockscreen">
<!-- Automatic element centering -->
<div class="lockscreen-wrapper">
<div class="lockscreen-logo">
<img src="/Images/^082594892CD6A1E2D2CF4B7361463D84FEF2B4C6FEBD2707B5^pimgpsh_fullsize_distr.png" alt="Cegos Logo">
</div>
<br />
<!-- User name -->
<div class="lockscreen-name"></div>
<!-- START LOCK SCREEN ITEM -->
<div class="lockscreen-item">
<!-- lockscreen image -->
<div class="lockscreen-image">
<img src="/Images/locked.jpg" alt="Locked Screen">
</div>
<!-- /.lockscreen-image -->
<!-- START LOCK SCREEN ITEM -->
<div class="lockscreen-item">
<!-- lockscreen image -->
<div class="lockscreen-image">
<img src="/Images/locked.jpg" alt="Locked Screen">
</div>
<!-- /.lockscreen-image -->
</div>
<!-- lockscreen credentials (contains the form) -->
<form class="lockscreen-credentials" action="RecoverPassword.aspx" method="post">
<div class="input-group">
<input id='user' type="Text" class="form-control" placeholder="Username">
<div class="input-group-btn">
<button id='enviar' type="submit" class="btn"><i class="fa fa-arrow-right text-muted"></i></button>
</div>
</div>
</div>
</form>
<!-- /.lockscreen credentials -->
</div>
<!-- /.lockscreen-item -->
<div class="help-block text-center">
Enter your username to retrieve your session
</div>
<div class="text-center">
<a href="../Default.aspx">Or sign in as a different user</a>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<%-- <br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />--%>
<br />
<div class="lockscreen-footer text-center">
<p style="height: 42px" align="center">© <%: DateTime.Now.ToShortDateString() %> - <strong>Cegos Elearning Reports</strong>
</div>
</div>
<!-- /.center -->
<!-- jQuery 2.2.0 -->
<script src="../../plugins/jQuery/jQuery-2.2.0.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="text/javascript">
$("#enviar").click(function () {
@SendEmail();//Insira aqui o código para chamar o sender email.
});
</script>
</form>
</body>
</html>
e tenho na propria página tenho uma class recoverpasssword e la defini o metodo sendemail() que tem o codigo de enviar email. Quando clico no botão na página para enviar email ele não faz post nem envia o mail. Podem-me ajudar por favor? Desculpem meus erros