show me your full code
Thanks for replying , updated it
still the same error, thanks for replying
What is your error?
What does normalizeRecipient function do? Don't you forget to return from that function? To use "return" keyword?
I think it should be public property instead of protected.
In BlogPublished.php-
public $blog;
public $user;
Check more: https://laravel.com/docs/6.x/mail#view-data
made them public , still the same issue
Dump your user data and show the result.
Try Mail::to($user) instead of Mail::to($user->email)
Can you share your full BlogPublished.php code? Don't post image.
Use 3 tilde(`) sign before and after your code.
i just made them back to protected
<?php
namespace App\Mail;
use App\Blog;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class BlogPublished extends Mailable implements ShouldQueue{
use Queueable, SerializesModels;
protected $blog;
protected $user;
public function __construct(Blog $blog, User $user)
{
$this->blog = $blog;
$this->user = $user;
}
public function build()
{
$this->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'))
->subject('A new Blog has been published')
->view('emails.newblog')
->with([
'user' => $this->user,
'blog' => $this->blog,
]);
return $this;
}
}
@shirshadebnath Honestly I cannot any issue so far. Can you clear your cache and try.
If still same, can you try this in your store method in the controller-
$users = User::get();
foreach($users as $user){
echo $user->email . "<br/>";
}
dd('');
I just want to see that what's returning there.
it is returning this:
public function store(Request $request){
//validate
$rules = [
'title' => ['required', 'min:10', 'max:160'],
'content' => ['required', 'min:102'],
];
$this->validate($request, $rules);
$input = $request->all();
//meta-stuff
$input['slug'] =uniqid() . Str::slug($request->title, '-');
$input['meta_title'] = Str::limit($request->title, 55);
$input['meta_description'] = Str::limit($request->content, 155);
//image-upload
if ($file = $request->file('featured_image')) {
$name = uniqid() . $file->getClientOriginalName();
$name = strtolower(str_replace(' ', '-', $name));
$file->move(public_path('/image/featured_image/'), $name);
$input['featured_image'] = $name;
}
//$blog = Blog::create($input);
$blogByUser = $request->user()->blogs()->create($input);
//sync with categories
if ($request->category_id) {
$blogByUser->category()->sync($request->category_id);
}
//mail
$users = User::all();
foreach($users as $user){
echo $user->email . "<br/>";
}
dd('');
Session::flash('blog_created_message', 'Blog Created!');
return redirect('/blogs');
}
Couldn't you add dd($address, $name, $property) on 578th line of Mailable.php and try to send mail again?
Seems good to me. Can I see your email environment variables? Do you set up everything properly?
Hmm, data seems correct.
Please, remove this dd and add dump($recipient) on 582th line.
@shirshadebnath
I see, that first $recipient is correct. But what about others? Please, change dd($recipient) to dump($recipient).
i did dump($recipient) but first it showed the output for a second and then redirected to error page and gave me the same error. therefore to show the output i got i dd($recipient)
thanks for patience till now
Oh. But you can log it. Try logger('RECIPIENT', [$recipient]); and explore storage/logs/laravel.log
laravel did not create logs folder under storage
May be you turned it off?
[2019-12-14 08:21:56] local.DEBUG: RECIPIENT [{"stdClass":{"email":"kirito.sd307@gmail.com"}}] [2019-12-14 08:21:56] local.DEBUG: RECIPIENT [null] [2019-12-14 08:21:56] local.ERROR: Trying to get property 'email' of non-object {"userId":1,"exception":"[object] (ErrorException(code: 0): Trying to get property 'email' of non-object at E:\dev\Laravel_projects\soporific_mind\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php:585) [stacktrace]
Please or to participate in this conversation.















