is it possible
to add an attach file to the contact us page?
and that admin will get this mail with the attachment
@model ContactUsModel
@using Nop.Web.Models.Common;
@{
Layout = "~/Views/Shared/_ColumnsTwo.cshtml";
//title
Html.AddTitleParts(T("PageTitle.ContactUs").Text);
}
<div class="page contact-page">
<div class="page-title">
<h1>@T("PageTitle.ContactUs")</h1>
</div>
@Html.Action("TopicBlock", "Topic", new { systemName = "ContactUs" })
<div class="page-body">
@Html.Widget("contactus_top")
@if (Model.SuccessfullySent)
{
<div class="result">
@Model.Result
</div>
}
else
{
using (Html.BeginForm("", "ContactUS", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="message-error">
@Html.ValidationSummary(true)
</div>
<div class="form-fields">
<div class="inputs-left">
<div class="inputs">
@Html.LabelFor(model => model.Email)
<div class="input-box">
@Html.TextBoxFor(model => model.Email, new { @class = "email", placeholder = T("ContactUs.Email.Hint") })
</div>
@Html.ValidationMessageFor(model => model.Email)
</div>
<br />
<div class="inputs">
@Html.LabelFor(model => model.FullName)
<div class="input-box">
@Html.TextBoxFor(model => model.FullName, new { @class = "fullname", placeholder = T("ContactUs.FullName.Hint") })
</div>
@Html.ValidationMessageFor(model => model.FullName)
</div>
@if (Model.DisplayCaptcha)
{
<div class="captcha-box">
@Html.Raw(Html.GenerateCaptcha())
</div>
}
</div>
<div class="inputs-right inputs">
@Html.LabelFor(model => model.Enquiry)
<div class="input-box">
@Html.TextAreaFor(model => model.Enquiry, new { @class = "enquiry", placeholder = T("ContactUs.Enquiry.Hint") })
</div>
@Html.ValidationMessageFor(model => model.Enquiry)
<br />
<br />
<div>
@Html.Label(T("Common.FileUploader.Upload").Text) <br />
@Html.TextBox("file", "", new { type = "file" }) <br />
</div>
</div>
</div>
<div class="buttons">
<input type="submit" name="send-email" class="button-1 contact-us-button" value=" @T("ContactUs.Button") " />
</div>
}
}
@Html.Widget("contactus_bottom")
</div>
</div>
[HttpPost, ActionName("ContactUs")]
[CaptchaValidator]
public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid, HttpPostedFileBase file)
{
//validate CAPTCHA
if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
{
ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
}
if (ModelState.IsValid)
{
string email = model.Email.Trim();
string fullName = model.FullName;
string subject = string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), _storeContext.CurrentStore.GetLocalized(x => x.Name));
var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
if (emailAccount == null)
emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
if (emailAccount == null)
throw new Exception("No email account could be loaded");
string from;
string fromName;
string body = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
//required for some SMTP servers
if (_commonSettings.UseSystemEmailForContactUsForm)
{
from = emailAccount.Email;
fromName = emailAccount.DisplayName;
body = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}",
Server.HtmlEncode(fullName),
Server.HtmlEncode(email), body);
}
else
{
from = email;
fromName = fullName;
}
//Attachment
string _path = "";
string _FileName = "";
if (file != null)
{
if (file.ContentLength > 0)
{
_FileName = Path.GetFileName(file.FileName);
_path = Path.Combine(@"d:\inetpub\webs\jurisit\tempDirectory", _FileName);
file.SaveAs(_path);
}
}
_queuedEmailService.InsertQueuedEmail(new QueuedEmail
{
From = from,
FromName = fromName,
To = emailAccount.Email,
ToName = emailAccount.DisplayName,
ReplyTo = email,
ReplyToName = fullName,
Priority = 5,
Subject = subject,
Body = body,
CreatedOnUtc = DateTime.UtcNow,
EmailAccountId = emailAccount.Id,
AttachmentFileName= _FileName,
AttachmentFilePath = _path
});
model.SuccessfullySent = true;
model.Result = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");
//activity log
_customerActivityService.InsertActivity("PublicStore.ContactUs", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));
return View(model);
}
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
return View(model);
}