1. Go to this page and download the library: Download yunusasuroglu/bulk-mailler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yunusasuroglu / bulk-mailler example snippets
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use YunusAsuroglu\BulkEmailler\Facades\BulkEmailer;
class BulkEmailController extends Controller
{
public function BulkMail()
{
return view('email-form');
}
public function sendBulkMail(Request $request)
{
$testEmails = "[email protected], [email protected]";
$testSubject = "Test Mailler";
$testMessage = "content";
$testItem = "item";
$testItem2 = "item2";
// You can add as much as you want here, it's up to you.
$emails = collect(explode(',', $testEmails))->map(fn($email) => trim($email))->filter(fn($email) => filter_var($email, FILTER_VALIDATE_EMAIL))->unique()->values()->all();
if (empty($emails)) {
return response()->json(['error' => 'Invalid email format.'], 400);
}
$subject = $testSubject;
$view = 'emails.bulkmailer';
$data = [
'message' => $testMessage,
'testItem' => $testItem,
'subject' => $testSubject,
'testItem2' => $testItem2,
];
try {
BulkEmailer::sendBulkMail($emails, $subject, $view, $data);
return response()->json(['message' => 'Emails sent successfully!']);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500); // Error Message View
}
}
}