email validation in laravel
'email' => 'required|email|unique:users,email',
//@sujay
email validation in laravel
'email' => 'required|email|unique:users,email',
//@sujay
send html email laravel
// $data => array of information passed to view
Mail::send('email_view', $data, function ($m) use ($user) {
$m->from("[email protected]", config('app.name', 'APP Name'));
$m->to($user->email, $user->email)->subject('Email Subject!');
});
Laravel 8 send email
How to send mail in Laravel 8 from https://realprogrammer.in/how-to-send-mail-in-laravel-8/
By: Atsu Emmanuel T.
Step 1: Create a Laravel 7 project
Step 2: Open laravel project set .env configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=gmail_password
MAIL_ENCRYPTION=ssl
Step 2: Add Route with routes/web.php
Route::get('send-mail','MailSend@mailsend');
Stage 3: Create Mail
In this progression, we will make mail class SendMail for email sending. Here we will compose code for which view will call and the question of the client. So we should run cry direction. you can check inside application/Mail/SendMail.php
php artisan make:mail SendMail
Add code within SendMail.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $details;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('Mail from Real Programmer')
->view('emails.sendmail');
}
}
Step 4: Create a controller
php artisan make:controller MailSend
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Mail\SendMail;
class MailSend extends Controller
{
public function mailsend()
{
$details = [
'title' => 'Title: Mail from Real Programmer',
'body' => 'Body: This is for testing email using smtp'
];
\Mail::to('[email protected]')->send(new SendMail($details));
return view('emails.thanks');
}
}
Step 5: Create Blade View
In this step, we will make a sharp edge view record and compose an email that we need to send. presently we simply keep in touch with some spurious content. make cry records on “messages” envelope.
resources/views/emails/sendmail.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Real Programmer</title>
</head>
<body>
<h1>{{ $details['title'] }}</h1>
<p>{{ $details['body'] }}</p>
<p>Thank you</p>
</body>
</html>
Step 6: Thanks message to show the user. create blade file within
view/emails/thanks.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Thanks</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="alert alert-success" role="alert">
Thanks, we will contact you soon
</div>
</div>
</body>
</html>
Step 7: Change config/mail.php
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Real Programmer'),
],
Step 8: Now run the server
php artisan serve
Step 9: now hit on URL
http://localhost:8000/send-mail
laravel send email
// admin.newsletters.send_email : is the blade that will have your email content
// 'newsletter' => $newsletter : is the collection to be used in the blade file
// function ($message) : the function email and the variable to be used in the message.
// use ($newsletter) : is the collection to be used in the message controller (e.g $message->to($newsletter->email))
// Swift_TransportException to check if it is real email
namespace App\Http\Controllers\Admin;
use Mail;
public function sendEmail(Newsletter $newsletter)
{
try {
Mail::send('admin.newsletters.send_email', ['newsletter' => $newsletter], function ($message) use ($newsletter) {
$message->from('[email protected]', 'eee-services.com');
$message->to('[email protected]')->subject('Newsletter');
});
} catch (\Swift_TransportException $e) {
if ($e->getMessage()) {
return redirect()->route('admin.newsletters.index');
}
}
return redirect()->route('admin.newsletters.index');
}
email validation in laravel
$validator = Validator::make($request->all(), []);
$validator->sometimes('email', 'unique:users,email', function ($input) {
return $input->email !== Auth::user()->email;
});
//@sujay
laravel mail send text
Mail::raw('Text to e-mail', function ($message) {
//
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us