Categories
Laravel

Laravel – Send email from any controller action

Laravel send email from any controllers. In this article, I am going to discuss the Mail API in the Laravel web framework. Laravel provides a clean, simple API over the popular SwiftMailer library with drivers for SMTP, Mailgun, sendmail etc. you are allowing to quickly get started sending mail.

The below are some easy steps to follow, and you will be able to send email in Laravel controller.

  • Install Laravel.
  • Create/Update Controller
  • Define a Controller Route.
  • SMTP configure in the .env file.
  • Create a Mailable class.
  • Create a Email Template.

Install Laravel.

Run following command to create new Laravel project.

Create/Update controller

Create new controller or update already defined method in your existing controller. Here I have create a new controller using below command.

After successfully create new controller you can update below code in your file.
app\Http\Controllers\EmailSendController.php

Define a route to send an email.

Now create a route in your web.php file to sending email to the user which you want.

Setting up SMTP details in .env file

We will use gmail SMTP to configure the settings in the .env file.

Create a Mailable class

Open your terminal and go to project root directory and type the following command.

So, it will create a file inside App\Mail\ContactUsMail.php. Now, this class catch form submitted data, and pass data to email template.

Create a email Template file in resources/views/emails/contact-us.blade.php

Now, you need to create a blade file inside the views/emails folder where you show email content and send form in laravel controller.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this article

Categories
Magento 2

Magento 2 – Set page title by layout XML or Controller

By default URL showing as title but thats not good look that appears on the title bar when created a new custom module. There are 2 (two) ways of Set page title by layout XML or Controller.

1. From frontend view layout module_controller_action.xml by head and title tag.

2. From frontend view layout module_controller_action.xml by referenceBlock page.main.title and set setPageTitle argument tag.

Set page title by PHP Controller

Also we can set page title by PHP controller file controllerName.php in method public function execute()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE