php - how to send email invitation with laravel and gmail -


i need send email invitation app new users. have no idea how manage controller? blade view

@extends('layouts.app')  <!-- main content --> @section('content') <div class="container">     <div class="row">         <div class="col-md-8 col-md-offset-2">             <div class="panel panel-default">                 <div class="panel-heading">send e-mail invitation</div>                 <div class="panel-body">                     @if (session('status'))                         <div class="alert alert-success">                             {{ session('status') }}                         </div>                     @endif                      <form class="form-horizontal" role="form" method="post" action="{{ url('/password/email') }}">                         {{ csrf_field() }}                          <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">                             <label for="email" class="col-md-4 control-label">e-mail address</label>                              <div class="col-md-6">                                 <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">                                  @if ($errors->has('email'))                                     <span class="help-block">                                         <strong>{{ $errors->first('email') }}</strong>                                     </span>                                 @endif                             </div>                         </div>                          <div class="form-group">                             <div class="col-md-6 col-md-offset-4">                                 <button type="submit" class="btn btn-primary">                                     <i class="fa fa-btn fa-envelope"></i> send invitation link                                 </button>                             </div>                         </div>                     </form>                 </div>             </div>         </div>     </div> </div> @endsection 

i need enter email address , send invitation mail. have configure gmail email client. can me?

you can send mails using laravel mail class this,

your controller should this:

use mail;  class emailscontroller { public function send(request $request) {     $email = $request->get('email');      mail::send('emails.send', ['email' => $email], function ($message) use ($email)     {         $message->from('me@gmail.com', 'your name');         $message->to($email);     });      return response()->json(['message' => 'invitation email sent!']); } } 

your view should in directory - resources/views/emails/send.php

<html>   <head></head>   <body style="background: black; color: white">     <h1>email invitation</h1>     <p>hello - {{$email}}</p>     <p>....</p>   </body> </html> 

note: remember configure .env file mails:

mail_driver=smtp mail_host=smtp.gmail.com mail_port=587 mail_username=myemail@gmail.com mail_password=apppassword mail_encryption=tls 

don't forget run php artisan config:cache after make changes in .env file. hope helps!

also remember configure mail.php file ioside config/mail.php this:

/* |-------------------------------------------------------------------------- | global "from" address |-------------------------------------------------------------------------- | | may wish e-mails sent application sent | same address. here, may specify name , address | used globally e-mails sent application. | */  'from' => ['address' => 'me@example.com', 'name' => 'your name'], 

configure file above, if want more - see this


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -