简体   繁体   中英

Laravel contact form email will not show message after email is sent

I have a contact form which sends emails to Mailtrap. The name and the email content display in the email body, but not the message. The following is my code:

Contact form blade (welcome.blade.php):

                    <form role="form" method="POST" action="/email/send">
              {{ csrf_field() }}
                <br style="clear:both">
                  <h3 style="margin-bottom: 25px; text-align: center;">Contact Form</h3>
                <div class="form-group">
                  <input type="text" class="form-control errorBorder" id="name" name="name" placeholder="Name">
                  <span id="warningLabel" class="warning wone" style="display:none;">Please enter name!</span>
                </div>
                <div class="form-group">
                  <input type="text" class="form-control" id="email" name="email" placeholder="Email" required>
                  <span id="warningLabel2" class="warning wtwo" style="display:none;">Please enter email!</span>
                </div>
                <div class="form-group">
                  <textarea class="form-control" type="textarea" id="query" placeholder="Message" maxlength="140" rows="7" name="message"></textarea>
                  <span id="warningLabel3" class="warning wthree" style="display:none;">Please enter message!</span>
                  <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
                </div>
                  <button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
            </form>

My email template (send.blade.php):

    <html  lang="en">
     <head></head>
     <body style="background: black; color: white">
      <h1>{!!$name!!}</h1>
    <h1>{!!$email!!}</h1>
     <p>{!!$query!!}</p>
     </body>
     </html>

And then my controller:

     namespace App\Http\Controllers;
     use Illuminate\Support\Facades\Mail;
     use Illuminate\Http\Request;
     use App\Mail\ContactMailer;

     class ContactEmailController extends Controller
     {
         public function send(Request $request)
{
  $name = $request->input('name');
  $email = $request->input('email');
  $query = $request->input('query');

  Mail::send('email.send', ['name' => $name, 'email' => $email, 'query' => $query], function($message){

                $message->from('examplefrom@gmail.com', 'Example');

                $message->to('Exampleto@gmail.com');
  });
}
     }

Try this in your controller

public function send(Request $request)
{
  $name = $request->name;
  $email = $request->email;
  $query = $request->message;

  Mail::send('email.send', ['name' => $name, 'email' => $email, 'query' => $query], function($message){

                $message->from('examplefrom@gmail.com', 'Example');

                $message->to('Exampleto@gmail.com');
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM