Custom Subject on Forms, not working

Hi everyone!

I still can’t personalize the subject in the mail that netlify sends (submission).

I want to receive the emails with the subject “New message” and I can’t, instead I receive them with the subject “[Netlify]”.

My code is:

<form
                            className="lg:w-1/3 md:w-1/2 bg-white flex flex-col md:ml-auto w-full md:py-8 mt-8 md:mt-0"
                            data-netlify="true"
                            data-netlify-honeypot="bot-field"
                            name="contacto"
                            method="post"
                            onSubmit={handleSubmit}
                        >
                            {/* Netlify Option */}
                            <input type="hidden" name="form-name" value="contact" />
                            <input type="hidden" name="subject" value="Nuevo mensaje"/>
                            <p hidden>
                                <label>
                                    <input name="bot-field" onChange={handleChange} />
                                </label>
                            </p>

I hope you can help me

Thank you!

Greetings

hi there, here is a relevant post:

Hello!

I have already read this article, I am not interested in removing the text “[Netlify]” at the beginning of the subject line, but what I want to achieve is that after “[Netlify]” comes “New Message”.
My code is:

<form
                            className="lg:w-1/3 md:w-1/2 bg-white flex flex-col md:ml-auto w-full md:py-8 mt-8 md:mt-0"
                            data-netlify="true"
                            data-netlify-honeypot="bot-field"
                            name="contacto"
                            method="post"
                            onSubmit={handleSubmit}
                        >
                            {/* Netlify Option */}
                            <input type="hidden" name="form-name" value="contact" />
                            <input type="hidden" name="subject" value="New message"/>
                            <p hidden>
                                <label>
                                    <input name="bot-field" onChange={handleChange} />
                                </label>
                            </p>

That is to say, that the final result will be like this:
“[Netlify] New message”

Greetings

Hi, since you are sending the submission via JS, you’ll need to make sure that those fields are being sent in your onSubmit handler function. Can you confirm that you have the field and the value when you send the submission?

Yes!

On “handleSubmit()” function i have:

fetch(’/’, {
method: ‘POST’,
headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ },
body: encode({
‘form-name’: form.getAttribute(‘name’),
…dataForm,
}),
})

When “dataForm” value is:

> const [dataForm, setDataForm] = useState({
    nombre: '',
    mail: '',
    telefono: '',
    mensaje: '',
    subject: 'New message'
});

That’s what you meant, isn’t it?

I hope you can help me.

Thank you

You’ll want to make sure you include the ‘subject’ field. Since you are using JS, you have to explicitly include any information you want to send. Like so:

fetch(’/’, {
method: ‘POST’,
headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ },
body: encode({
‘form-name’: form.getAttribute(‘name’),
'subject': "New message",
…dataForm,
}),
})

excelent!

Thats works!

i was missing single quotes in key subject.

Thanks!