First off, I apologize as I feel this question has been asked a ton of times on Stack Overflow, however I've tried reviewing some of those solutions but they still don't seem to help. I'm just trying to find out if anything within my code stands out for a reason for my problem.
I have an mvc website currently hosted on a GoDaddy shared hosting account. I'm trying to setup a simple contact form that sends an email to the site owner. When I submit the form, no errors are reported, however the email is not being sent. I've already spoken several times to GoDaddy support and they say it's nothing on their end. In addition, when testing from my localhost (using in my web.config), the email saves successfully to the directory.
A few details:
Page I'm having the problem on (for the phone, use only numbers. I'm still working on it): https://solarsafely.com/Home/Contact
GoDaddy Hosting: shared
Email I'm trying to use to send: Outlook 365 email (purchased from GoDaddy)
Here's my mvc controller for sending:
public async Task<ActionResult> Contact(Email email)
{
if(ModelState.IsValid)
{
try
{
string body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("[email protected]"));
mail.From = new MailAddress(email.From);
mail.Subject = "You have a new message from SolarSafely.com - Contact Us";
mail.Body = string.Format(body, email.Name, email.From, email.Body);
mail.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient())
{
await smtp.SendMailAsync(mail);
return RedirectToAction("Sent");
}
}
catch(Exception exc)
{
ViewBag.Error = exc.Message;
}
}
return View(email);
}
Web.config:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="relay-hosting.secureserver.net" port="25" />
</smtp>
</mailSettings>
</system.net>
Any idea why my email is not sending? Thanks
Try setting it up temporarily using a GMAIL address.
I checked here: https://www.godaddy.com/help/send-form-mail-using-an-smtp-relay-server-953 and you may have to explicitly set the Authentication and ssl settings in web.config.