0

I'm trying to receive the email from a lead popup form to receive the details on an email. Everything is added and I'm getting "Message Sent" but still get getting emails.

This is my HTML

<div class="modal fade" id="enquire-now" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><img src="images/close.png" alt="close button"></button>
            <h4 style="color:#6e08a1; font-size:20px;" class="modal-title" align="center"><strong>Please Leave Your Detail Here</strong></h4><br>
            <form onsubmit="sendEmail(); reset(); return false;">
                <div class="form-group">
                    <input type="text" id="name" class="form-control"  placeholder="Full Name" data-rule="maxlen:32" data-msg="Please enter at least 4 chars" required /> 
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="email" placeholder="Email ID" data-rule="email" data-msg="Please enter a valid email" required  pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"/>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="phone"  placeholder="Mobile No" data-rule="maxlen:4" data-msg="Please enter at least 10 chars of Number" required pattern="[0-9]{10}"/>
                </div>
                <div class="form-group">
                    <textarea class="form-control" id="message"  placeholder="Message" rows="2"></textarea> 
                </div>

                <div align="center">
                    <button name="submit" class="button" type="Submit">Send Message</button>
                    <!--<input name="submit" type="Submit" id="submit" class="button" value="Send Message" />-->
                </div> 
            </form>
            </div>
        </div>
    </div>
</div> 

JS

<script type="text/javascript">

        $(window).load(function () {
            setTimeout(function () {
                $('#enquire-now').modal('show');
                // alert("hello how are you");
            }, 5000);
        });
    </script>
    <script src="https://smtpjs.com/v3/smtp.js"></script>
    <script>
        function sendEmail(){
            Email.send({
                SecureToken: "aaf0aeef-223a-4c04-9d70-7a3f8ff5b404",
    To : 'email id',
    From : document.getElementById("email").value,
    Subject : "This is the subject",
    Body : "Name: " + document.getElementById("name").value + "<br> Email: " + document.getElementById("email").value + "<br> Phone No: " + document.getElementById("phone").value + "<br> Message: " + document.getElementById("message").value
}).then(
  message => alert("Message Sent Succesfully")
);
        }
    </script>

Tried without token too and also with regenerate token too.

jabaa
  • 5,844
  • 3
  • 9
  • 30
  • *Tried without token too* - What did you use instead of `SecureToken`? Did you use the `Host`, `Username` and `Password` config options? It might also be a problem with Elasticmail. You can test your code with Gmail, though it requires some additional setup within your Google account. – FiddlingAway Jan 28 '23 at 13:23
  • Tried with host username and password too but still not getting email –  Jan 28 '23 at 13:26
  • Do you see the request in the network monitor? – jabaa Jan 28 '23 at 14:02
  • Not getting any in elacticemail dashboard but I'm getting successful message. –  Jan 28 '23 at 14:24

1 Answers1

0

By your provided code above, it seems that you want to receive the email with the user's input email value. However, it might not work due to the SMTP JS policy to prevent spoofed email sending. So you need to verify a sender domain or verify sender email.

If want to use a verified sender email, you can only use the Form: as your verified sender email. So if your verified email is verified-email@example.com. Your sendEmail() function should be:

function sendEmail(){                                                   
    Email.send({
        SecureToken: "aaf0aeef-223a-4c04-9d70-7a3f8ff5b404",
        To : 'verified-email@example.com',
        From : 'verified-email@example.com',
        ReplyTo: document.getElementById("email"),
        Subject : "This is the subject",
        Body : "Name: " + document.getElementById("name").value + "<br> Email: " + document.getElementById("email").value + "<br> Phone No: " + document.getElementById("phone").value + "<br> Message: " + document.getElementById("message").value
    }).then( message => alert("Message Sent Successfully") );
}

Please keep in mind that if you are using a Gmail account as the verified email, you should turn on the 2-Step Verification and allow secure app access in Gmail, there is a post about this.

If that is not the case, I also had a similar situation and found out mine was in the spam mailbox. You could check that out if you haven't.

Alternatively, you may want to try using a different JS email sender tool for the similar result, like Formspree or EmailJS or phpMailer (if you have a backend). You can find out more in here.