{"flag":true,"single":true,"pageTitle":"How to Send Emails in Laravel Using Controller","post":{"id":124,"user_id":"1","slug":"how-to-send-emails-in-laravel-using-controller-uudh","title":"How to Send Emails in Laravel Using Controller","body":"<p>Sending emails is an important part of any web application, and Laravel provides a simple and elegant way to send emails using its built-in Mail facade. In this tutorial, we'll show you how to send emails in Laravel using controllers, models, and routes. We'll start by creating a new controller, then we'll write the code to send the email, and finally, we'll create a route to trigger the email sending process. So, let's get started!<\/p>\r\n<p>1. First, create a new controller using the following command:<\/p>\r\n<pre class=\"language-markup\"><code>php artisan make:controller EmailController<\/code><\/pre>\r\n<p>2. Next, open the EmailController.php file located in the \"app\/Http\/Controllers\" directory and add the following code:<\/p>\r\n<pre class=\"language-markup\"><code>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Support\\Facades\\Mail;\r\n\r\nclass EmailController extends Controller\r\n{\r\n    public function sendEmail()\r\n    {\r\n        Mail::raw('This is the content of mail body', function($message) {\r\n            $message-&gt;from('admin@abc.com', 'GOODTeam');\r\n            $message-&gt;to('rizikmw@gmail.com');\r\n            $message-&gt;subject('ABC');\r\n        });\r\n\r\n        return 'Send Email Successfully';\r\n    }\r\n}\r\n<\/code><\/pre>\r\n<p>3.Next, create a route to the sendEmail method in the web.php file located in the \"routes\" directory:<\/p>\r\n<pre class=\"language-markup\"><code>Route::get('\/rhn', [\\App\\Http\\Controllers\\EmailController::class, 'sendEmail']);<\/code><\/pre>\r\n<p>4. Finally, you can test the route by visiting the \"\/rhn\" URL in your browser.<\/p>\r\n<p><strong>OUTPUT<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>^ \"Send Email Successfully\"<\/code><\/pre>","category_id":"2","is_private":"0","created_at":"2023-04-23T01:05:36.000000Z","updated_at":"2023-04-23T01:05:36.000000Z","category":{"id":2,"user_id":"1","name":"Laravel Core","slug":"laravel-nhyt","parent_id":"1","created_at":"2023-03-14T03:58:27.000000Z","updated_at":"2023-03-20T11:30:50.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"Sending emails is an important part of any web application, and Laravel provides a simple and elegant way to send emails using its built-in  - How to Send Emails in Laravel Using Controller (Updated: April 23, 2023) - Read more about How to Send Emails in Laravel Using Controller at my programming site [SITE]","categories":[]}