Developer forum

Forum » CMS - Standard features » "Forms for editors" doesn't send email

"Forms for editors" doesn't send email

Gaetan Di Caro
Reply

Hello,

 

I created a form with a custom template that I implemented via a "forms for editors" paragraph module. Everything seems to work fine, except that the email doesn't get sent... I know my SMTP settings are correct because other parts of my website send emails fine.

Attached are my template and my paragraph settings.

 

Any idea ?

Thanks !

2015-12-16_14_42_43-.png

Replies

 
Nicolai Høeg Pedersen
Reply

Hi Gaetan

Only thing I can think of, is that the form does not have the email field specified. You have to do that explicitly on the form settings - select the field that contains the email.

BR Nicolai
 

Gaetan
 
Gaetan Di Caro
Reply

Unfortunately no, it is defined. I also tried to put an email address instead of using the email field, but no luck either.

 
Gaetan Di Caro
Reply

The other mail that is sent is sent from custom code using EmailHandler.Send, but I suppose this just takes the smtp settings that are defined in the administration ?

 

edit : also this other email appears in the log. The one I'm trying to send leaves no trace at all there

 
Nicolai Høeg Pedersen
Reply

Does it work with auto setting instead of using your own "Newsletter.cshtml" template?

 
Nicolai Høeg Pedersen
Reply

Your template seems to be missing the method attribute on the form - so it is not POSTED to the page.

 
Gaetan Di Caro
Reply

Hmm, it's not ? Maybe the forum messed it up, it seems that I can't post it here properly either as an .cshtml attachment or in a pre markup, so here it is attached as a .txt.

 
Nicolai Høeg Pedersen
Reply

My bad. But does it send an email using auto mode?

 
Gaetan Di Caro
Reply

Ok I experimented a bit and it seems like the problem comes from the javascript code I add to the onsubmit. If I delete it, the mail gets sent.

Do you know any way to have it work ?

 

Thanks !

 
Nicolai Høeg Pedersen
Reply

Put your js in a method along with the forms js - just ensure the right syntax. Then call that method onsubmit.

 
Gaetan Di Caro
Reply

Hmm still not.

I have this on the page :

<script type="text/javascript">
    function submitNewsletter() {
        Cookies.set('newslettershown', '1', { path: '/', expires: 14 });
        alert('Thanks for subscribing !');
        s=function(e){e.elements['FormCH1_h'].value='cd9d509819568683a215395f36af011d';e.elements['_sys_to_email'].value='';e.setAttribute('action', 'Default.aspx?ID=132');return true};return s(this);
    }
</script>

Then my onsubmit looks like this : onsubmit="return submitNewsletter();"

 

But it still doesn't work, the same way as before. My two lines of js get executed correctly, but the form doesn't get posted correctly.

 
Nicolai Høeg Pedersen
Reply

Try this:

<script type="text/javascript">
    function submitNewsletter() {
        Cookies.set('newslettershown', '1', { path: '/', expires: 14 });
        alert('Thanks for subscribing !');
     return s();   
    }
s=function(e){e.elements['FormCH1_h'].value='cd9d509819568683a215395f36af011d';e.elements['_sys_to_email'].value='';e.setAttribute('action', 'Default.aspx?ID=132');return true};return s(this);
</script>

and on the form, onsubmit="return submitNewsletter();"

 
Gaetan Di Caro
Reply

Thanks, we're making progress :)

Now the form gets posted and I get the email. However the form redirects me to a wrong URL.

Let's say i'm on this page : http://mytestdomain/da-dk/forside.aspx

I see that the javascript changes the action of the form to be "Default.aspx?ID=132", which corresponds to the same page. However I'm redirected to this : http://mytestdomain/da-dk/Default.aspx?ID=132&s=dgBBADkANwBlAEYAdgBkAEsAMwBZAD0A

Which is wrong (404 error), because I'm not on the root of the website, but on /da-dk/. Is there any way to mitigate this ?

Thanks !

 

edit : btw, the "Form.Onsubmit" includes a return, so in order to not have errors I needed to write @formOnSubmit.Replace("return s(this);", string.Empty)

 
Gaetan Di Caro
Reply

Hmm I'm having something weird. The email suddenly didn't get sent anymore even though we didn't touch the template. I tried some stuff but nothing seems to work. The form is sending correctly and I'm redirected to the right page but it doesn't actually do anything. I get no javascript error

My template :

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using System;
@using System.Web;
@using Dynamicweb.Rendering;

@{
    string formCssClass = GetString("Form.CssClass");
    string formSystemFields = GetString("Form.SystemFields");
    string formId = GetString("Form.HtmlId");
    string formOnSubmit = GetString("Form.OnSubmit");
}

<script type="text/javascript">
    function_@formOnSubmit.Replace("return s(this);", string.Empty).Replace("return true", string.Empty)
 
    function submitNewsletter(form) {
        Cookies.set('@Pageview.Area.Item["NewsletterCookieName"]', '1', { path: '/', expires: 14 });
        alert('@Translate("NewsletterConfirmation", "Thanks for subscribing !")');
        function_s(form);
        return true;
    }
</script>

<form method="post"
      enctype="multipart/form-data"
      class="@formCssClass"
      id="@formId"
      onsubmit="return submitNewsletter(this);">

    @formSystemFields

    <span class="newsletter-text"><h3>@Translate("NewsletterText", "Subscribe to our newsletter")</h3></span>

    <input type="text" id="Name" name="Name" placeholder='@Translate("NewsletterNamePlaceHolder", "Name")' required class="form-control" />
    <input type="email" id="Email" name="Email" placeholder='@Translate("NewsletterEmailPlaceHolder", "Email")' required class="form-control" />
    <input type="submit" id="Send" name="Send" value='@Translate("NewsletterSendButtonText", "Send")' class="btn btn-default" />
</form>

What it looks like in the html :

<script type="text/javascript">
    function_s=function(e){e.elements['FormCH1_h'].value='db94fed3609a6d58c4124176c8162f97';e.elements['_sys_to_email'].value='';e.setAttribute('action', 'Default.aspx?ID=132');};
 
    function submitNewsletter(form) {
        Cookies.set('newslettershown', '1', { path: '/', expires: 14 });
        alert('Thanks for subscribing !');
        function_s(form);
        return true;
    }
</script>

<form method="post" enctype="multipart/form-data" class="" id="dw-form-13" onsubmit="return submitNewsletter(this);">

    <input name="FormPID" value="1888" type="hidden">
<input name="FormID" value="13" type="hidden">
<input name="cmd" value="save" type="hidden">
<input name="_sys_to_email" value="bot@dynamicweb.com" type="hidden">
<input name="FormCH1_h" value="" type="hidden">
<input name="FormCH1_f" value="9becc1c37e19da00f0e84f938c65e0f6" type="hidden">
<input name="FormCH1_s" value="0dd65e8dd4cfe9e0837c18620877ea83" type="hidden">
<input name="FormCH1_i" value="e925e97e7aafb9df31a599b175bc5228" type="hidden">


    <span class="newsletter-text"><h3>Gå ikke glip af
vores nyhedsbreve</h3></span>

    <input id="Name" name="Name" placeholder="Navn" required="" class="form-control" type="text">
    <input id="Email" name="Email" placeholder="Email" required="" class="form-control" type="email">
    <input id="Send" name="Send" value="Send" class="btn btn-default" type="submit">
</form>

And the content of the post request :

 

 
Nicolai Høeg Pedersen
Reply

I would test the mail logs in the filemanager.

 
Gaetan Di Caro
Reply

Hi,

No trace of the emails in the log file. The other part of my website which sends emails works fine.

 
Nicolai Høeg Pedersen
Reply

I doubt that...

Anyways - create a case with the URL to the solution so helpdesk can help you.

It is not your template.

 

You must be logged in to post in the forum