public IActionResult SendEmail(string fromName, string fromEmail, string message, [ModelBinder(Name = "g-recaptcha-response")] string recaptchaResponse, bool isAJAX = false) { var sendEmail = true; var success = false; var errorMessage = ""; if (_googleRecaptchaSettings.IsEnabled) { var recaptchaResult = _googleRecaptcha.IsNotARobot(recaptchaResponse, Request.HttpContext.Connection.RemoteIpAddress.ToString()); sendEmail = recaptchaResult.Success; if (!recaptchaResult.Success) { errorMessage = "Recaptcha error : "; if (recaptchaResult.Errors != null && recaptchaResult.Errors.Count > 0) { foreach (var error in recaptchaResult.Errors) { errorMessage += "[" + error + "] "; } } } } if (sendEmail) { if (_emailSender.SendEmail(fromName, fromEmail, message, out errorMessage)) { success = true; } } if (isAJAX) { if (success) { return(new JsonResult(success)); } else { // Log the error return(StatusCode(500, new { error = "There was an error sending your message.", detail = errorMessage })); } } else { return(Redirect("/Contact?success=" + success.ToString().ToLower())); } }