I know this question is asked many times but I could not found the answer
I am using this method to sending email
Mail::send('dynamic_email_template',$data, function ($message) {
$message->from('sales#scoopscreamery.pk', 'Contact');
$message->to('hamzaqureshi401#gmail.com')->subject('Contact');
});
and getting this error No hint path defined for [mail].
the error cause is i am sending table in email using #component('mail::table') in dynamic blade view so then i tried to differernt technique of code but in this i am getting mail but without (user input) {{ $name }} , {{ $email }} , {{ $messae1 }} can any one help me
yo get input data in email
controller
$data = [
'name' => $request->name,
'email' => $request->email,
'message1' => $request->message1
];
Mail::to('hamzaqureshi401#gmail.com')->send(new \App\Mail\SendMail($data));
my model is
class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $data;
public function __construct(array $data)
{
$this->data = $data;
}
public function build()
{
return $this->subject('Mail from Online Web Tutor')
->markdown('dynamic_email_template',['data'=>$this->data]);
}
and my dynamic blade is
<p>Hi, This is {{ $name }}</p>
<p>I have some query like {{ $email }}.</p>
<p>It would be appriciative, if you gone through this feedback {{ $message1 }}.</p>
#component('mail::table')
| Laravel | Table | Example |
| ------------- |:-------------:| --------:|
| Col 2 is | Centered | $10 |
| Col 3 is | Right-Aligned | $20 |
#endcomponent
the error cause is I am sending table in email using #component('mail::table') in dynamic blade view so then I tried to differernt technique of code but in this I am getting mail but without (user input) {{ $name }} , {{ $email }} , {{ $messae1 }} can any one help me yo get input data in email
There may be some error in mail or notification inside your vendor folder re-export the component using publish command
php artisan vendor:publish --tag=laravel-mail
Related
Is it possible to assign a blade template to a model?
Instead of doing this:
#php $contact = Contact::find(1); #endphp
#include('contact', ['contact' => $contact])
I'd like to just do:
#php $contact = Contact::find(1); #endphp
{{ $contact }}
But latter obviously just spits out the model in json.
It is possible with PHP's __toString() magic method: https://www.php.net/manual/en/language.oop5.magic.php#object.tostring
Let's make an example for default User.php model.
First, create a blade file for that model, lets create that as /resources/views/model/user.blade.php and a dummy component;
<h1>{{ $user->name }}</h1>
<p>{{ $user->created_at->diffForHumans() }}</p>
Now make this default __toString() for User model.
Add this to app/Models/User.php ;
/**
* #return string
*/
public function __toString(): string
{
return view('model.user', ['user' => $this])->render();
}
Now you can test it directly in your routes/web.php ;
Route::get('test', function () {
echo \App\Models\User::first();
});
Or try to echo it in any view as;
{!! $user !!}
You can't use {{ $user }} because you need that HTML tags, so you have to use it as {!! $user !!}
I want to send email in laravel. 2 user get different email content. So, here is my code.
TransactionController.php
use App\Mail\MailFruitCustomer;
use App\Mail\MailFruitSeller;
$data = array(
'fruitid' => 'F01',
'fruitname' => 'Banana',
'customercode' => 'B2345',
'sellercode' => 'S9546'
);
Mail::to(customer1#mail.com)->send(new MailFruitCustomer($data));
Mail::to(seller1#mail.com)->send(new MailFruitSeller($data));
MailFruitCustomer.php (In Mail folder)
public function __construct($data){
$this->data = $data;
}
public function build(){
$result = $this->from('admin#mail.com')
->subject('Customer New Transaction')
->markdown('emails/customerreceipt')
->with('data', $this->data);
return $result;
}
MailFruitSeller.php (In Mail folder)
public function __construct($data){
$this->data = $data;
}
public function build(){
$result = $this->from('admin#mail.com')
->subject('Seller New Transaction')
->markdown('emails/sellerreceipt')
->with('data', $this->data);
return $result;
}
customerreceipt.blade.php
#component('mail::message')
Customer Receipt Detail
Fruit ID: {{ $data['fruitid'] }}
Fruit Name: {{ $data['fruitname'] }}
Customer Code: {{ $data['customercode'] }}
Thank you.<br>
#endcomponent
sellerreceipt.blade.php
#component('mail::message')
Seller Receipt Detail
Fruit ID: {{ $data['fruitid'] }}
Fruit Name: {{ $data['fruitname'] }}
Seller Code: {{ $data['sellercode'] }}
Thank you.
#endcomponent
It is working and both user get email with different content. But the process take longer time. Is there any method of mail in laravel that i could apply?
Any help will be grateful. Thank you.
You are searching for Queues: https://laravel.com/docs/7.x/queues
You create a job that sends the mail and queue the job. Laravel can send the response faster and the Mail is sent asynchronous.
Additional: https://laravel.com/docs/7.x/mail#queueing-mail
I continue to learn Queues and create job that sends mail.
I got another problem and fix it with help from others. Thank you.
Here is the link https://stackoverflow.com/a/63370095/12022919.
I am trying to create a table which the user can sort
I created the following two routes
route::get('/manager', 'Manager\DeadlineController#index')->middleware(['auth', 'auth.manager'])->name('manager.index');
route::post('/manager/{name_id}', 'Manager\DeadlineController#sortByName')->middleware(['auth', 'auth.manager'])->name('manager.sortByName');
from my php artisan route:list
| | GET|HEAD | manager | manager.index | App\Http\Controllers\Manager\DeadlineController#index | web,auth,auth.manager |
| | POST | manager/{name_id} | manager.sortByName | App\Http\Controllers\Manager\DeadlineController#sortByName | web,auth,auth.manager |
and set up my controller as follows
public function index()
{
return view('deadline.index')
->with([
'modules' => Module::all(),
'name_id' => 0
]);
}
public function sortByName($name_id){
if($name_id == 0){
$sortedModule = Module::orderBy('name', 'DESC')->get();
}
else{
$sortedModule = Module::orderBy('name', 'ASC')->get();
}
return view('deadline.index')
->with([
'modules' => $sortedModule,
'name_id' => 1
]);
}
in my view i use the following link to sort
<th scope="col">NAME</th>
but when i use this link in my view I am somehow redirected to my GET route because i get the following error
The GET method is not supported for this route. Supported methods: POST.
What am I missing or doing wrong? Any help or tips will be appreciated. Please ask if I need to provide more details
Update
I change the link in my view to a form tag with a submit button and now it works
<th scope="col">
<form action="{{ route('manager.sortByName', $name_id) }}" method="POST">
#csrf
<button type="submit">NAAM</button>
</form>
</th>
When you click on <a> tag it does GET request, so you need to change your route from POST to GET, also returning view as a response to post method is not good idea,the best solution is GET route
Below is my mail function:
How to can I pass an array to mail function?
public function mail(Request $request , $id) {
$data=[
'owner'=>MyRoom::where('id',$id)->get(),
'data2'=>$request->all(),
];
Mail::send('emails.mail' , $data, function($message) use ($data){
$message->to($owner->created_by->email , $owner->created_by->name)
->subject('Room showing Request From OpenRoomList');
$message->from('regmibipin13#gmail.com','OpenRoomList');
});
echo "Email Send check your inbox";
}
Firstly instead of doing get which will give you a collection, do :
'owner' => MyRoom::find($id);
In your resources/emails/mail.blade.php blade file you can directly use $owner and $data2 variables using blde syntax like : {{ $owner->somecolumn }} and {{ $data2['somefield'] }}
I am firing an event that sends an email to the user when he requests a password reset.
Here's the event listener that will send an email
class SendResetPasswordLink {
public function handle(UserForgotPassword $event) {
Mail::to($event->user)
->queue(new SendResetPasswordToken($event->user->passwordResetToken));
}
}
Here's my mail class:
class SendResetPasswordToken extends Mailable {
use Queueable, SerializesModels;
public $token;
public function __construct(PasswordReset $token) {
$this->token = $token;
}
public function build() {
return $this->subject('Reset your MyEngine password')
->markdown('emails.password.reset')
->text('emails.password.reset_text');
}
}
I have email files (both html and text) available at
resources/views/emails/password/reset.blade.php
and
resources/views/emails/password/reset_text.blade.php
It is not working and I am getting the following error:
"View [] not found. (View: /home/vagrant/Laravel/youtube/resources/views/emails/password/reset.blade.php)"
What do I need to do? All my blade files are in place.
Here's my reset.blade.php
#component('mail::message')
<strong>Hello {{ $token->user->getFirstNameOrUserName() }}!</strong>
You are receiving this email because we received a password reset request for your account.
If you did not request a password reset, no further action is required.
#component('mail::button', [
'url' => route('password.reset', ['token' => $token,]) . '?email=' . urlencode($token->user->email)
])
Reset Password
#endcomponent
Thanks,<br>
{{ config('app.name') }}
#endcomponent
<hr>
If you’re having trouble clicking the <strong>"Reset Password"</strong> button, copy and paste the URL below into your web browser:<br>
<small>{{ route('password.reset', ['token' => $token,]) . '?email=' . urlencode($token->user->email) }}</small>
#endcomponent
I found the answer,
For whatever reason I had closed(ended) the markdown component twice #endcomponent.