Laravel Mail

By ukmodak | March 31st 2024 10:38:02 AM | viewed 1052 times

add any one of the following set code to .env file to setup mail:

MAIL_DRIVER=smtp
MAIL_HOST=mail.ukmodak.com
MAIL_PORT=587
MAIL_USERNAME=test@ukmodak.com
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info@ukmodak.com
MAIL_FROM_NAME=QRIOUS

#MAIL_DRIVER=smtp
#MAIL_HOST=mail.ukmodak.com
#MAIL_PORT=465
#MAIL_USERNAME=test@ukmodak.com
#MAIL_PASSWORD=pass
#MAIL_ENCRYPTION=ssl
#MAIL_FROM_ADDRESS=info@ukmodak.com
#MAIL_FROM_NAME=QRIOUS

#MAIL_DRIVER=sendmail
#MAIL_HOST=mail.qriusbd.com
#MAIL_PORT=587
#MAIL_USERNAME=test@qriusbd.com
#MAIL_PASSWORD=pass
#MAIL_ENCRYPTION=ssl
#MAIL_FROM_ADDRESS=info@qriusbd.com
#MAIL_FROM_NAME=QRIOUS

Run the following code:

D:\xampp_726\htdocs\ptm > php artisan config:cache

Add a class in this location:App\Mail

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;


use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;
use App\User;


class UserRegisMail extends Mailable
{
    use Queueable, SerializesModels;


    public  $to_email ="";
    public  $to_name ="";
	public  $cc_email ="";
    public  $cc_name ="";
    public  $subject ="";
    
    public  $userIns = null;
    public  $password = null;
    public  $businessOwnerUserIns = null;
    public  $ecShowroomIns = null;
    
    
    
    public function __construct($to_email,$to_name,$cc_email,$cc_name,$subject,$userIns,$password,$businessOwnerUserIns,$ecShowroomIns)
    {
                $this->to_email = $to_email;
                $this->to_name = $to_name;
				$this->cc_email = $cc_email;
                $this->cc_name = $cc_name;
                $this->subject = $subject;
                $this->userIns = $userIns;
                $this->password = $password;
                $this->businessOwnerUserIns = $businessOwnerUserIns;
                $this->ecShowroomIns = $ecShowroomIns;
    }

   
    public function build()
    {
       
        return $this->view('emails.user_regi_mail')
                //->from($address, $name)
                //->replyTo($address, $name)
                ->subject($this->subject);
    }
   
}

create the view in the location:resources\views\emails\user_regi_mail.blade.php


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">   
</head>
<body style="font-size:12px;color:#000000;">
  <div style="width:100%;padding:0 10px;clear:both;">
            <div style="clear:both;">
                         <div style="width:150px;float:left;vertical-align: bottom;">
                                <a href="{{\URL::to('/')}}"><img style="width:150px;" src="{{$message->embed(asset('public/images/upload/logo/qrius.png')) }}"></a>
                         </div>
                         <div style="width:300px;float:right;vertical-align: baseline;position:absolute;right:10px;top:60px;">
                                        <?php
                                          $date = \Carbon\Carbon::now('Asia/Dhaka');
                                        ?>
                                        @if($date)
                                         {{'Date: '}} {{\Carbon\Carbon::parse($date)->format('F jS Y h:i:s A')}}               
                                        @endif
                        </div>
            </div>
                  
    <div style="clear:both;border-top:1px solid #cccccc;"> </div>
    <div style="clear:both;">
        <h5>Welcome to {{@$userIns->first_name}}{{@$userIns->last_name}}</h5>
           <p> 
               Your User Id: {{@$userIns->email}} / {{@$userIns->mobile}}<br/>
               Your password: {{@$password}}<br/>
           </p>              
    </div>
     <div style="clear:both;">
         <div style="clear:both;border-top:1px solid #cccccc;"> </div>
            <p class="footerPara marginZero" align="center">
                Copyright 2020 by QRIUS. All Rights Reserved.
                  |  Powered by QRIUS  
            </p>
    </div>
</div>   
</body>
</html>

Now call this class from any controller as follows:


<?php namespace App\Http\Controllers\Ecommerce;

use App\Mail\UserRegisMail;
use Illuminate\Support\Facades\Mail;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Carbon\Carbon;
use DB;
use Auth;
use Illuminate\Support\Facades\URL;

class EcOrderController extends Controller {

 public function orderSuc(Request $request){
 
     $sendmailSts ="ok";
	 
     $userRegisMail = new UserRegisMail($to_email,$to_name,$cc_email,$cc_name,$subject,$userIns,$password,$businessOwnerUserIns,$ecShowroomIns);  // to render html
         
            $sendmailSts = Mail::to($to_email,$to_name)
                                 ->cc($cc_email,$cc_name)
                                 ->send($userRegisMail);
         
            if($sendmailSts == null){
               return 1; 
            }else{
                return 0;
            }
	}
}	
			
bONEandALL
Visitor

Total : 27273

Today :9

Today Visit Country :

  • United States
  • Sweden
  • Singapore
  • Russia