using System; using System.Net; using System.Net.Mail; using System.Web; using System.Web.UI; using System.Collections.Generic; using System.Text; using System.Web.Services; public partial class ContactForm : Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static object SendContact(string firstName, string lastName, string email, string phone, string message, string consent) { try { if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(message)) { return new { success = false, message = "Faltan campos obligatorios" }; } SmtpClient smtpClient = new SmtpClient("mail.sirgo.cl", 587); smtpClient.Credentials = new NetworkCredential("contacto@sirgo.cl", "Bnjklmdfwgzp0qotvsxr"); smtpClient.EnableSsl = true; MailMessage mailMessage = new MailMessage(); mailMessage.SubjectEncoding = System.Text.Encoding.UTF8; mailMessage.BodyEncoding = System.Text.Encoding.UTF8; mailMessage.From = new MailAddress("contacto@sirgo.cl", "Formulario de Contacto"); mailMessage.To.Add(email); mailMessage.Subject = "Nuevo mensaje de contacto: "; StringBuilder body = new StringBuilder(); body.AppendLine("NUEVO MENSAJE DE CONTACTO"); body.AppendLine("================================"); body.AppendLine(); body.AppendLine("Nombre: " + firstName + " " + lastName); body.AppendLine("Email: " + email); body.AppendLine("Teléfono: " + (string.IsNullOrEmpty(phone) ? "No proporcionado" : phone)); body.AppendLine(); body.AppendLine("Mensaje:"); body.AppendLine(message); body.AppendLine(); body.AppendLine("Consentimiento: " + (consent == "on" ? "SÍ" : "NO")); body.AppendLine(); body.AppendLine("Enviado el: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")); mailMessage.Body = body.ToString(); //mailMessage.IsBodyHtml = true; smtpClient.Send(mailMessage); return new { success = true, message = "Mensaje enviado correctamente. Nos pondremos en contacto pronto." }; } catch (Exception ex) { return new { success = false, message = "Error: " + ex.Message }; } } }