dimanche 28 janvier 2018

Laravel Not Sending Mail

I have a controller function for a contact us form which is supposed to work with a controller function to send an email and then launch a modal upon form submission. The modal launches but the email never gets to the address and I checked mailgun but there are no errors.

Here's my form and modal

<form class="form" id="contact-form" action="contactus" method="post">
                <div class="form-group">
                    <label for="name">Name</label>
                    <input type="text" class="form-control" name="name" id="name" placeholder="Enter your name" required>
                </div>
                <div class="form-group">
                    <label for="email">Email Address</label>
                    <input type="email" class="form-control" name="email" id="email" placeholder="Enter your email" required>
                </div>
                <div class="form-group">
                    <label for="topic">Title</label>
                    <input type="text" class="form-control" name="topic" id="topic" placeholder="Enter the Title" required>
                </div>
                <div class="form-group">
                    <label for="details">Details</label>
                    <textarea class="form-control" name="details" id="details" placeholder="In a few words let us know how we might be of service" maxlength="2000" required></textarea>
                    
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>
            <div class="modal fade" id="myModal">
                <div class="modal-dialog">

                    <div class="modal-content">

                        <!-- Modal Header -->
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">Welcome Back!</h4>
                        </div>

                        <!-- Modal Body -->
                        <div class="modal-body">
                            <h1>Hello Readers!</h1>
                        </div>

                        <!-- Modal Footer -->
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>

                    </div>
                </div>
            </div>
        </div>

Here's my controller code

public function contactUs(Request $request)
{

    Mail::to($request->email)->send(new ContactUsNotification($request->name));

    $contactus = new ContactUs;

    dd($request->input);

    $contactus->name = $request->input['name'];
    $contactus->email = $request->input['email'];
    $contactus->topic = $request->input['topic'];
    $contactus->message = $request->input['details'];

    $contactus->save();


    $data = $request->input['name'];

    return response()->json($data, 200, [], JSON_PRETTY_PRINT);
}

Then here's my js which fires only after the document has loaded

$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('[name="_token"]').val()
  }
});

e.preventDefault(e);

$.ajax({
    type: 'POST' ,
    url: '/contactus',
    data: $(this).serializeArray(),
    datatype: 'json',
    delay: 2000,
    success: function(data) {

        var options = {
            backdrop: true,
            keyboard: false,
            show: true,
            remote: false
        };

        $("#myModal").modal(options);

        console.log(data);
    },

    error: function(data) {
        console.log("Many problems ",data);
    } 
})

I'd appreciate some help on this



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rNJiuW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire