0

I am developing a project with Vue.js, so to manage sending email through the contact form instead of the backend, I am using Email.js. I followed steps as below:

  1. Add an email services
  2. Create an email template
  3. Install EmailJS
  4. Create contact form

I hosted it on Netlify. Problem is, the sending email works on localhost and in the permalink on Netlify, but not in the production deploy:enter image description here Anyone have any idea why the EmailJS works properly in the localhost and in the permalink but not in the production deploy?

This is my contact form:

<template>
    <form class="contact-form" @submit.prevent="submitForm">
        <div class="form-row">
            <input type="text" placeholder="Emri" v-model="form.name" required />
            <input type="text" placeholder="Mbiemri" v-model="form.surname" required />
        </div>
        <input type="email" placeholder="Emaili" v-model="form.email" required />
        <input type="tel" placeholder="Numri i telefonit" v-model="form.phoneNumber" required />
        <textarea placeholder="Mesazhi juaj..." v-model="form.message" required></textarea>
        <label class="form-checkbox">
            <input type="checkbox" id="agree" v-model="form.agree" required />
            <span class="checkmark"></span>
            Unë pajtohem me politikën e privatësisë
        </label>

        <button type="submit">Dërgo mesazhin</button>
    </form>
</template>
<script>
import emailjs from 'emailjs-com';

export default {
    data() {
        return {
            form: {
                name: '',
                surname: '',
                email: '',
                phoneNumber: '',
                message: '',
                agree: false
            }
        };
    },
    methods: {
        submitForm() {
            if (!this.form.agree) {

                alert('Ju duhet të pajtoheni me politikën e privatësisë.');
                return;
            }
            emailjs.init('PUBLIC_KEY');

            const templateParams = {
                from_name: `${this.form.name} ${this.form.surname}`,
                from_email: this.form.email,
                phone: this.form.phoneNumber,
                message: this.form.message
            };
            emailjs.send(
                'SERVICE_ID',       
                'TEMPLATE_ID',      
                templateParams,
                'PUBLIC_KEY'      
            ).then(() => {
                alert('Mesazhi u dërgua me sukses!');
                this.resetForm();
            }).catch((error) => {
                console.error('Gabim gjatë dërgimit:', error);
                alert('Ndodhi një gabim gjatë dërgimit.');
            });
        },
        resetForm() {
            this.form = {
                name: '',
                surname: '',
                email: '',
                phoneNumber: '',
                message: '',
                agree: false
            };
        }

    }

};
</script>

I tried to check if the email service, email template, account is OK or maybe has any mistake, but their configuration is ok.

1
  • The configuration would need to be verified. You say it's ok but we have no proof of that. It needs to be shown that your production URL matches one of the allowed domains in your emailjs config. Other things that should be mentioned is whether or not any errors appear in console or network tab of browser dev tools. Regarding the code, emailjs.send() has wrong 4th parameter, instead of your public key the documentation explains this parameter is an optional object of type "Options" Commented Jun 30 at 21:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.