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 use PHPMailer with React?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer to attach a ZIP file?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I configure PHPMailer to support Polish characters?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I view the log for my PHPMailer emails?
- How can I use PHPMailer in Yii 1?
- How do I use PHPMailer with IMAP?
- How do I check which version of PHPMailer I'm using?
See more codes...