In the world of web development using laravel, sending email is one of the most common tasks. Although many developers are familiar with this process, sometimes we forget how to do it without using view or mailable. In this article, we will discuss how to send an email on Laravel without the need to create a special appearance (view) or mailable.
Laravel, a very popular PHP framework, provides facilities that are easy to use for sending emails. By using Laravel’s default features, we can send emails very efficiently. Here are simple steps to send email without view or mailable on Laravel:
Also read: Laravel: Send an Email Without Letter
Step 1: File Configuration .env
The first step that needs to be taken is to ensure that your email configuration is correct in the file .env
. Make sure you have set a parameter like MAIL_MAILER
, MAIL_HOST
, MAIL_PORT
, MAIL_USERNAME
And MAIL_PASSWORD
correctly according to the email account you want to use.
Step 2: Send an email without view
First, you need to import the class Mail
From Namespace Illuminate\Support\Facades
In your controller file.
use Illuminate\Support\Facades\Mail;
Next, you can use the function Mail::raw()
to send an email without view. This function allows you to send emails with ordinary text content or HTML directly through the program code.
public function kirimEmailTanpaView()
{
$pesan = "Ini adalah pesan teks dari Laravel tanpa menggunakan view.";
Mail::raw($pesan, function($message) {
$message->to('[email protected]', 'Penerima')->subject('Subjek Email');
});
return "Email berhasil dikirim!";
}
In the example above, $pesan
is the contents of the email message you want to send. You can replace it according to your needs.
To see the code source can click here
Conclusion
That’s the simple way to send an email on Laravel without using view or mailable. By using functions Mail::raw()
You can send emails quickly and efficiently directly through the program code without the need to create a special look. Hopefully this article is useful for you in developing your Laravel projects!
Game Center
Game News
Review Film
Rumus Matematika
Anime Batch
Berita Terkini
Berita Terkini
Berita Terkini
Berita Terkini
review anime
Comments are closed, but trackbacks and pingbacks are open.