install phpmailer laravel code example
Example 1: phpmailer with laravel
composer require phpmailer/phpmailer
Example 2: phpmailer with laravel
<?php
namespace App\Http\Controllers;
use PHPMailer\PHPMailer;
class testPHPMailer extends Controller
{
public function index()
{
$text = 'Hello Mail';
$mail = new PHPMailer\PHPMailer();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "testpass";
$mail->SetFrom("[email protected]", 'Sender Name');
$mail->Subject = "Test Subject";
$mail->Body = $text;
$mail->AddAddress("[email protected]", "Receiver Name");
if ($mail->Send()) {
return 'Email Sended Successfully';
} else {
return 'Failed to Send Email';
}
}
}