Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emailjs | Message can not be sent. | SOLVED #36

Open
konstantinosiakovou opened this issue Nov 13, 2024 · 0 comments
Open

Emailjs | Message can not be sent. | SOLVED #36

konstantinosiakovou opened this issue Nov 13, 2024 · 0 comments

Comments

@konstantinosiakovou
Copy link

konstantinosiakovou commented Nov 13, 2024

About this code removed the 'gmail' and every time i make any change like insert public key, trying to send the message it fails.
const sendEmail = (e) => {
e.preventDefault()
emailjs.sendForm('gmail','service_','template_', form.current, {
publicKey: '*',
})
.then(
() => {
alert('Message successfully sent!')
window.location.reload(false)
},
() => {
alert('Failed to send the message, please try again')
}
)
}

Solved by attached the sendEmail function to an event and used e.preventDefault() to prevent the default form submission behavior:

emailjs.init({ publicKey: '* });

const sendEmail = (e) => {
e.preventDefault();

emailjs.sendForm('service_*', 'template_*', form.current, '*')
    .then((result) => {
        console.log('SUCCESS!', result.text);
        alert('Message sent successfully!');
    }, (error) => {
        console.log('FAILED...', error);
        alert('Failed to send message. Please try again.');
    });

};
@konstantinosiakovou konstantinosiakovou changed the title Emailjs | Message can not be sent. Emailjs | Message can not be sent. | SOLVED Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant