PHP code example of kilroyweb / email-verification
1. Go to this page and download the library: Download kilroyweb/email-verification library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers\Email\Verification;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class VerificationController extends Controller
{
public function create(){
$user = \Auth::user();
$user->requestEmailVerification();
return redirect('/account')->withSuccess('Verification email sent!');
}
public function show($token){
$user = \App\User::findByEmailVerificationToken($token);
if(!$user){
abort(404);
}
$user->verifyEmail();
\Auth::login($user);
return redirect('/account')->withSuccess('Your email address has been verified!');
}
}
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailVerification extends Mailable
{
use Queueable, SerializesModels;
public $verifiableModel;
public function __construct($verifiableModel)
{
$this->verifiableModel = $verifiableModel;
}
/**
*
*Build the message.
*
* @return $this
*/
public function build()
{
$verifiableModel = $this->verifiableModel;
$this->to($verifiableModel->email);
return $this->view('email.email-verification.create',[
'verifiableModel'=>$verifiableModel,
]);
}
}
@extends('layouts.email.app')
@section('content')
<h2>Click here to verify your email address:</h2>
<p><a href="{{ url('/email/verification/'.$verifiableModel->getEmailVerificationToken()) }}">Verify My Email</a></p>
@endsection