Trying to get Laravel 5 email to work
To get Laravel 5's email functionality to work, you will need to configure your SMTP settings in the .env
file, located in the root directory of your Laravel project.
Here is an example of what your SMTP settings might look like:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
Watch a video course Git & GitHub - The Practical Guide
Once you have updated your .env
file with your SMTP settings, you can use Laravel's built-in email functions to send emails. Here is an example of how you might use the Mail
facade to send an email:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
class EmailController extends Controller
{
public function send()
{
$data = ['name' => "Virat Gandhi"];
Mail::send(['text' => 'mail'], $data, function ($message) {
$message->to('[email protected]', 'Tutorials Point')->subject('Laravel Basic Testing Mail');
$message->from('[email protected]', 'Virat Gandhi');
});
echo "Basic Email Sent. Check your inbox.";
}
}
You can also use the send
method on the Mail
facade to send emails using a blade template:
Mail::send('emails.welcome', $data, function ($message) {
$message->from('[email protected]', 'John Doe');
$message->to('[email protected]', 'Jane Doe');
$message->subject('Welcome to My Site');
});
I hope this helps! Let me know if you have any questions or if you need further assistance.