Search code examples
emailflutter-webcontact-form

Flutter web contact form EmailJs ( sending emails empty )


I was trying to create a portfolio in flutter web, then i wanted to add a contact form. I used EmailJS. When I hit the "send" button I get emails but they are blank...

How can i fix this? can you help me?

Here is my EmailJS template

I get this mail when i press the button

sendEmail

and this is part of my code

Padding(
                          padding: const EdgeInsets.symmetric(vertical: 8),
                          child: TextField(
                            controller: messageController,
                            style: const TextStyle(color: Colors.white),
                            minLines: 10,
                            maxLines: 15,
                            decoration: const InputDecoration(
                                hintText: 'Enter Your Message',
                                hintStyle: TextStyle(color: Colors.grey),
                                border: OutlineInputBorder(
                                  borderSide: BorderSide(
                                    color: Color(0xFF66FcF1),
                                  ),
                                ),
                                contentPadding: EdgeInsets.all(10.0)),
                          ),
                        ),
                        Row(
                          children: [
                            Expanded(
                              child: OutlinedButton(
                                onPressed: () {
                                  sendEmail(
                                      email: '',
                                      message: '',
                                      name: '',
                                      subject: '');
                                },
                                child: const Padding(
                                  padding: EdgeInsets.all(8.0),
                                  child: Text(
                                    'Submit',
                                    style: TextStyle(
                                      color: Color(0xFF66FcF1),
                                      fontSize: 16,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),

Solution

  • Everything works correctly since your message is sent, except on line message: ' ', you didn't add the message content that should be sent.

    The solution is this,

    onPressed: () {
                   sendEmail(
                   email: '',
                   message: _messageController.text.trim(),
                   name: '',
                   subject: '');
         },
    

    I would also suggest you provide fields to fill all the other fields for a better end user experience.