Error in Sending Ajax form

Asked

Viewed 28 times

1

Hello, I need a help, when I try to send it displays the message successfully and dps displays the error message when sending, when I enter the dev mode of the browser and see the contact.blade.php it appears that error there on top of utf-8 and does not send, when I take the java script it sends the email but pq am on localhost

This is the error that appears when you send the contact forms:

{message: "Caracteres UTF-8 malformados, possivelmente codificados incorretamente",…} mensagem: "Caracteres UTF-8 malformados, possivelmente codificados incorretamente" exceção: "InvalidArgumentException"

A part of the html form:

   @csrf
        <div class="container">
            <div class="row">
                <div class="text-center col-12">
                    <div class="form text-left">
                        <div class="row">
                            <div class="col-sm-8">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <div class="input-group">
                                                <input name="nome" type="text" class="form-control form-input"
                                                    placeholder="Nome">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <div class="input-group">
                                                <input name="email" type="text" class="form-control form-input"
                                                    placeholder="E-mail">
                                            </div>
                                        </div>
                                    </div>
                                </div>

Controller with a sending function:

$form = $request->all();

        Mail::to(['****@*****.***'])
            ->send(new SendMail($form,'Formulário de Contato'));
        if (Mail::failures()) {
            echo '0';
            exit;
        }
        echo '1';

The model shipped:

class SendMail extends Mailable
{
    use Queueable, SerializesModels;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($form,$subject)
    {
        $this->form = $form;
        $this->subject = $subject;
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
        ->from('****','Fale Conosco')
        ->subject("Fale Conosco | ".$this->subject)
        ->view('emails.contact',$this->form);
    }
} 

javascript file:

$(document).ready(function() {
    $('#contact-form').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: $(this).serialize(),
            beforeSend: function(data) {
                alert('Enviando')
            },
            success: function(data) {
                alert('Menssagem enviada com sucesso');
            },
            error: function(data) {
                alert('Erro ao tentar envia o E-mail');
            }
        })
    });
});

What should I do? Can you help me?

  • Hello @leo Burik welcome to Stack Overflow! Be specific in your question, talk about the mistake, but also tell us what to fix so we can help you.

  • 1

    Hello then when I try to send it displays the message successfully and dps displays the error message when sending, when I enter the dev mode of the browser and see the contact.blade.php it appears that error there on top of utf-8 and does not send, when I take the java script it sends the email but pq am on localhost

  • Edit your question and put that comment above the error message, so the community experts will have a better parameter to help you.

  • All right, thank you !

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.