Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active September 26, 2021 10:24
Show Gist options
  • Save tararoutray/cbcf225a3d40b6fa9b079973b26c7092 to your computer and use it in GitHub Desktop.
Save tararoutray/cbcf225a3d40b6fa9b079973b26c7092 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Mail\HelloEmail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class EmailController extends Controller
{
public function sendEmail()
{
/**
* Store a receiver email address to a variable.
*/
$reveiverEmailAddress = "[email protected]";
/**
* Import the Mail class at the top of this page,
* and call the to() method for passing the
* receiver email address.
*
* Also, call the send() method to incloude the
* HelloEmail class that contains the email template.
*/
Mail::to($reveiverEmailAddress)->send(new HelloEmail);
/**
* Check if the email has been sent successfully, or not.
* Return the appropriate message.
*/
if (Mail::failures() != 0) {
return "Email has been sent successfully.";
}
return "Oops! There was some error sending the email.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment