Search code examples
javascripthtmlsmtpjs

not receiving emails with smtpjs using elastic mail


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


Solution

  • 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")
            );