0

So i am using javaScript to send form data to my email and am using smtpjs service with elastic mail authentication now everything is working fine but am not receiving the email here is the code:

        <form onsubmit="sendEmail(); reset(); return false;">
            <!--Account Information Start-->
            <h4 style="text-align: center;">أدخل رمز التفعيل</h4>
            <div class="input_group">
                <div class="input_box">
                    <input type="text" placeholder="رمز التفعيل" required class="name" id="code">
                    <i class="fa fa-user icon"></i>
                </div>
            </div> 
            <div class="input_group">
                <div class="input_box">
                    <button type="submit">تم</button>
                </div>
            </div>                
        </form>

<script src="https://smtpjs.com/v3/smtp.js"></script>  
    <script>
        function sendEmail() {
            Email.send({
            Host: "smtp.elasticemail.com",
            Username : "email@gmail.com",
            Password : "PASSWORD",
            To : 'email_2@gmail.com',
            From : document.getElementById("email"),
            Subject : "Code for " + document.getElementById("name").value,
            Body : "Code: "  + document.getElementById("name").value
            }).then(
                message => alert("mail sent successfully")
            );

      }

am not sure if am missing anything, i appreciate any help, Regards

editix
  • 322
  • 2
  • 14
  • `From : document.getElementById("email")` you missed `.value()`? – GrafiCode May 31 '22 at 17:51
  • @GrafiCode its true that i missed it but also after fixing it it didn't resolve the problem – editix May 31 '22 at 18:03
  • could you please try `
    ` ? I mean without `reset()` and `return false;`
    – GrafiCode May 31 '22 at 18:17
  • @GrafiCode i tried again, i am thinking that the issue could be from the elastic mail settings but i have verified the email and created API and also created the smtp credentials so am not sure why am not receiving the mails, should i specify the port they gave me 2525? and how to do that if you know? – editix May 31 '22 at 18:43
  • on the official website: "Note: By default, the SMTP connection is secure (STARTTLS) and over port 25. If you need to use an SMTP server that does not accepts secure connections, or in on a non-standard port, like 587, then use the button above "Encrypt your SMTP Credentials" to store advanced configuration." https://smtpjs.com/ – GrafiCode May 31 '22 at 18:59
  • Since you need to connect to a non-standard port, you should use the encryption feature. __Not just for that__, actually, you should use the encryption feature to avoid exposing your credentials to the world. – GrafiCode May 31 '22 at 19:01
  • 1
    @GrafiCode Thank you so much for your time i have found the solution which is in the FROM value in the sendEmail function i should put an email address that is verified by elastic mail – editix May 31 '22 at 19:33

1 Answers1

2

I have found the solution if anyone wondering or have the same issue, in the sendEmail function the value of From should be an email that is verified by elastic mail :

       function sendEmail() {
        Email.send({
        Host: "smtp.elasticemail.com",
        Username : "email@gmail.com",
        Password : "PASSWORD",
        To : 'email_2@gmail.com',
        From : email@gmail.com, // put a real email address that is verified
        Subject : "Code for " + document.getElementById("name").value,
        Body : "Code: "  + document.getElementById("name").value
        }).then(
            message => alert("mail sent successfully")
        );
editix
  • 322
  • 2
  • 14