hello i would like to know where could be a mistake in this is the code i get a error saying /home/runner/work/_temp/f7610f6f-2495-4196-8736-156d1c0a06ea.sh: line 1: syntax error near unexpected token `(‘
Error: Process completed with exit code 2.
im trying to get a mail when somebody presses a button on my website i have connected it with sendgrid but i still get the error please help thanks
this is the code
name: Email Notification
on:
push:
branches:
– main
jobs:
sendEmail:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Install PowerShell
run: |
sudo apt-get update
sudo apt-get install -y powershell
pwsh --version # Verify the installation
- name: Capture form data
id: capture-form-data
run: |
echo "::set-output name=data::$(echo '{"name": "'${{ env.INPUT_NAME }}'", "email": "'${{ env.INPUT_EMAIL }}'", "message": "'${{ env.INPUT_MESSAGE }}'"}')"
- name: Send email
env:
TO_EMAIL: ${{ secrets.TO_EMAIL }}
FROM_EMAIL: ${{ secrets.FROM_EMAIL }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
run: |
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const formData = JSON.parse(process.env.CAPTURE_FORM_DATA);
const message = {
to: 'spyfilip@gmail.com', // Replace with your email address
from: 'kontaktstranka@gmail.com', // Replace with the sender email address
subject: 'Form Submission',
text: `A form submission was received:nnName: ${formData.name}nEmail: ${formData.email}nMessage: ${formData.message}`
};
sgMail.send(message)
.then(() => {
console.log('Email sent successfully');
})
.catch((error) => {
console.error('Error sending email:', error);
});