Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To pick a random email address from an array for Laravel's mailable feature, you can use the array_rand() function in PHP.

Here's an example code snippet:

// Define an array of email addresses
$emails = [
    'john@example.com',
    'jane@example.com',
    'bob@example.com',
    'alice@example.com'
];

// Pick a random email address using array_rand()
$randomEmail = $emails[array_rand($emails)];

// Use the $randomEmail variable in your mailable code
Mail::to($randomEmail)->send(new YourMailable());

In this example, the array_rand() function picks a random index from the $emails array, and returns the corresponding email address. You can then use this email address in your Mail::to() function to send your mailable to a random recipient.