each type of mail is one class in app/mail directoru
to genearte mailabe class
php artisan make:mail learvernemail
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=73@gmail.com
MAIL_PASSWORD=""
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=ie73@gmail.com
MAIL_FROM_NAME="No Reply"
CC_MAIL="73@gmail.com"
BCC_MAIL="jdv@gmail.com"
core php
php mailer
php artisan make:mail maillabletempalte
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class MaillableTemplate extends Mailable
{
use Queueable, SerializesModels;
public $details;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
// $template = 'emails.demoMail';
if ($this->details){
$template = 'emails.'.$this->details['mail_type'];
} else {
$template ='emails.demoMail';
}
return $this->markdown($template)
->subject($this->details['subject'])
->with('details', $this->details);
}
}
use queueable -> trait
blade
resources/mail
<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Send Email Example</title>
</head>
<body>
<h1>This is test mail from </h1>
<p>Laravel 8 send email example</p>
</body>
</html>
in controller
use App\Mail\MaillableTemplate;
use App\Jobs\SendEmail as SEJ;
$details = [
'title' => 'Successfully updated Profile',
'description'=>'description',
'url' => 's',
'subject' => 'Successfully updated Profile',
'email' => 'narayanavamsikrishna@gmail.com',
'password' =>'s',
'username' => 's',
'mail_type' =>'registrationTemplate'
];
dispatch(new SEJ($details));
SEND EMIAL JOB
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Mail\MaillableTemplate;
use Mail;
class SendEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $details;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$myccEmail=env('CC_MAIL');
$mybccEmail =env('BCC_MAIL');
$mail= Mail::to($this->details['email'])->cc($myccEmail)->bcc($mybccEmail);
$mail->send(new MaillableTemplate($this->details));
}
}
MAIL/WELCOMEMAIL.PHP
CONTROLLER
BCC(mailinator)
S
select the local language
send from languages folder
testmail.blade.php
html_mail.blade.phpmessage.tabline
html_mail.blade.php
Which mailer is used in Laravel 8?
Marked Answer : Swift Mailer
Correct Answer : Swift Mailer
Mailable classes stored in _________ directory.
Marked Answer : app/Mail
Correct Answer : app/Mail
Which method is used to attach files in mailable class?
Marked Answer : attach()
Correct Answer : attach()
Which method is used to attach inline attachments?
Marked Answer : attach()
Correct Answer : embed()
Which method is used to add bcc in mail?
Marked Answer : bcc()
Correct Answer : bcc()
No comments:
Post a Comment