phpmailerHow can I send emails using PHPMailer in Laravel 8?
Sending emails using PHPMailer in Laravel 8 is achieved by using the send
method of the Mail
facade. This method accepts a Message
instance, which is created by using the message
method of the Mail
facade.
The message
method accepts a Closure
that contains the message configuration such as the subject, from address, to address, and the message body.
Example code
Mail::send(
['text'=>'mail'],
$data,
function($message) use ($data)
{
$message->to($data['email'], $data['name'])
->subject('Welcome to My Site!');
}
);
The send
method also accepts a Mailable
instance, which is created by extending the Mailable
class. This class contains methods to configure the message such as from
, subject
, view
, attach
, etc.
Example code
use App\Mail\WelcomeMail;
Mail::to($data['email'], $data['name'])->send(new WelcomeMail());
The send
method returns a Swift_Message
instance, which is an object representation of the message.
Helpful links
More of Phpmailer
- How can I configure PHPMailer to support Polish characters?
- How can I use PHPMailer without SMTP secure?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer to send a file?
- How do I set the X-Mailer header using PHPMailer?
- How do I use PHPMailer to attach a ZIP file?
- How can I send a UTF-8 encoded email using PHPMailer?
- How can I use PHPMailer with XAMPP on a localhost?
- How do I check which version of PHPMailer I'm using?
- How can I configure PHPMailer to ignore TLS certificate errors?
See more codes...