When i am trying to attach large files greater than 1MB this error appears
message :fwrite(): send of 5067 bytes failed with errno=11 Resource temporarily unavailable
file: "/var/www/html/test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php"
and here is my code
in module.php
Mail::to($data[EMAIL])->send(new SigningApplication($data));
in SigningApplication.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SigningApplication extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* #return void
*/
public $user_data;
public function __construct($user_data)
{
$this->user_data = $user_data;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->from(config('email'), config('mail.from')['name'])
->view('emails.signing_application')
->attach($this->user_data['pdf'],['mime' => 'application/pdf'])
}
}
Related
I try to send an email to a new user. But I get this error, but I don't understand what is wrong.
TypeError: Illuminate\Mail\PendingMail::send(): Argument #1
($mailable) must be of type Illuminate\Contracts\Mail\Mailable,
App\Events\UserStored given, called in
/Users/kate_kimt/laravel/laravel_block/app/Listeners/SendMailNewUser.php
on line 31 in file
/Users/kate_kimt/laravel/laravel_block/vendor/laravel/framework/src/Illuminate/Mail/PendingMail.php
on line 122
UserStored.php:
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\User;
class UserStored
{
public User $user;
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
SendMailNewUser.php:
namespace App\Listeners;
use App\Events\UserStored;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Mail;
use Illuminate\Mail\Mailable;
class SendMailNewUser extends Mailable
{
/**
* Create the event listener.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* #param \App\Events\UserStored $event
* #return void
*/
public function handle(UserStored $event)
{
Mail::to($event->user->email)->send(new UserStored($event->user));
}
}
When adding an item to the queue, for some reason the handle method is not being called.
The Log entry in __construct is appearing but when attempting to log in handle(), nothing appears.
The method i'm using to dispatch is ProcessImport::dispatch($path, $task->task_id);
My queue service is configured to use Redis, and redis is storing all the data accordingly.
I am using Laravel 8. What could be wrong?
<?php
namespace App\Jobs;
use App\Models\Tasks;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Http\Controllers\Products\Products;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Queue;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobProcessed;
use Throwable;
class ProcessImport implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $file_path;
protected $response;
protected $task;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct($path, $task_id)
{
Log::info("Importing products (construct)");
$this->task = Tasks::where('task_id', $task_id)->first();
$this->file_path = $path;
Log::info('Importing ' . $path);
}
private function getFilePath() {
return $this->file_path;
}
/**
* Handle a job failure.
*
* #param \Throwable $exception
* #return void
*/
public function failed(Throwable $exception)
{
$this->task->failed($exception->getMessage());
}
/**
* Get the cache driver for the unique job lock.
*
* #return \Illuminate\Contracts\Cache\Repository
*/
public function uniqueVia()
{
return Cache::driver('redis');
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
Log::info("Importing products (handle)");
$this->task->start();
$products = new Products();
$products->importProductsFromCSV($this->getFilePath());
$this->task->success();
Log::info("End of importing products..");
}
}
You've just pushed the jobs onto the queue but haven't started a worker to process them. You can run the worker with:
php artisan queue:work
I am trying to send a email in Laravel. It works finicky to say at least. got couple of classes for sending email for different conditions. Only difference would be markup of sent email and blade file which data is sent to before sending. I tried using use Mail; in controller from whom i'm sending it, with \Mail::(... and use Illuminate\Support\Facades\Mail; with Mail::(... and vice-versa. So it ain't it.
Here are the mail files:
ToHR file:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\User;
class toHR extends Mailable
{
use Queueable, SerializesModels;
public $user;
public $job;
public $jobCount;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($user,$job,$jobCount)
{
$this->user = $user;
$this->job = $job;
$this->jobCount = $jobCount;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->markdown('mail.toHR');
}
}
ToHRFirst file:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\User;
class toHRFirst extends Mailable
{
use Queueable, SerializesModels;
public $user;
public $job;
public $jobCount;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($user,$job,$jobCount)
{
$this->user = $user;
$this->job = $job;
$this->jobCount = $jobCount;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->markdown('mail.toHRFirst');
}
}
And my test file JobCreated:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\User;
class JobCreated extends Mailable
{
use Queueable, SerializesModels;
public $user;
public $job;
public $jobCount;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($user,$job,$jobCount)
{
$this->user = $user;
$this->job = $job;
$this->jobCount = $jobCount;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->markdown('mail.job-created');
}
}
They'll all the same, yet error occurs. What gives? Did i miss something? Any help will be appreciated, just point me in the right direction.
Code which i use to send email:
Variables used get values from queries which are rather long, but they are not an issue anyways.
Ver1:
Mail::to($user->email)->send(
new JobCreated($user,$job,$jobCount)
);
Ver2:
Mail::to($user->email)->send(
new toHRFirst($user,$job,$jobCount)
);
Ver3:
Mail::to($user->email)->send(
new toHR($user,$job,$jobCount)
);
Sending works if it's used first version. Other cannot be found and that's the error.
Try renaming your files to follow Laravel convention;
You can see that the file JobCreated has a class JobCreated. You need to respect the uppercases:
Rename the ToHR.php file into ToHr.php, then:
Rename the class class toHRinto class ToHr
Rename the ToHRFirst.php file into ToHrfirst.php, then:
Rename the class class toHRFirst into class ToHrfirst
Or if you want to keep the uppercases, just rename the classes like so:
class toHRinto class ToHR
class toHRFirstinto class ToHRFirst
Finally, don't forget to import your job class at the top of your controller file (or wherever you use the Mail method:
use App\Mail\ToHR;
and
use App\Mail\ToHRFirst;
I have trouble when I try to send Mail.
My code to send mail:
$data = $request->all();
$result = Mail::to(env('MAIL_ADMIN'))->send(new ContactFormMail($data['name'],$data['email']));
ContactFormMail is my controller with code below:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ContactFormMail extends Mailable
{
use Queueable, SerializesModels;
protected $name;
protected $email;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($name, $email)
{
$this->name=$name;
$this->email=$email;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->markdown('emails.contact-form')
->with([
'name'=>$this->name,
'email'=>$this->email,
])
->subject('New mail');
}
}
I have error on file
/home/mpfmfoff/public_html/vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php
protected function registerManager()
{
$this->app->singleton('queue', function ($app) {
// Once we have an instance of the queue manager, we will register the various
// resolvers for the queue connectors. These connectors are responsible for
// creating the classes that accept queue configs and instantiate queues.
return tap(new QueueManager($app), function ($manager) {
$this->registerConnectors($manager); // Here I have error
});
});
}
"Class 'Illuminate\Queue\QueueManager' not found"
I try to send notification via pusher when user submitted new order.
in my CartController where I save data into my orders table I have:
<?php
use App\Events\UserOrdered;
//codes....
public function checkout(Request $request) {
//rest of the code
Auth::user()->orders()->save($order);
event(new UserOrdered($order));
//Cart::clear();
Session::flash('success', 'Thank you. Your order has been received.');
return redirect()->route('ordersindex');
}
when I hit to save my order i will get 404 NOT FOUND on event(new UserOrdered($order));
Here is my Event code:
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Order;
class UserOrdered implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $order;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('order-placed');
}
}
This is my Listener code:
<?php
namespace App\Listeners;
use App\Events\UserOrdered;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendNotification
{
/**
* Create the event listener.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* #param UserOrdered $event
* #return void
*/
public function handle(UserOrdered $event)
{
$pusher->trigger($event, 'order-placed', $order);
}
}
PS: When I try my pusher from pusher website Debug Console i can get notification. Whatever problem is, is from event and listener.
Any idea?
UPDATE
update 2
I managed to get pusher to work (i know is not the best way but it works at least).
here is my listener now:
<?php
namespace App\Listeners;
use App\Events\UserOrdered;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pusher\Pusher;
use Mail;
class SendNotification
{
/**
* Create the event listener.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* #param UserOrdered $event
* #return void
*/
public function handle(UserOrdered $event)
{
Mail::to($event->order->buyer_email)->send(new UserOrdered($event->order));
$options = array(
'cluster' => 'ap1',
'encrypted' => true
);
$pusher = new Pusher(
'xxxxx', //id
'xxxxx', //key
'xxxx', //secret_key
$options
);
$pusher->trigger('UserOrdered', 'order-placed', $event->order);
}
}
What I need?
Pusher will show notification in admin as new order placed. done
I also want to send 2 emails one to admin to say he/she has new
order, and another to user to say that we received his/her order.
mail function:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Order;
class UserOrdered extends Mailable
{
use Queueable, SerializesModels;
public $order;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->from('noreply#tester.com')->subject('Your Order recieved!')->markdown('emails.orders');
}
}
Progress: In order to send emails I added Mail::to in my listener as you see above, and added code below to my controller function:
//rest of the code...
Auth::user()->orders()->save($order);
$user = $order->buyer_email;
event(new UserOrdered($order));
Mail::to($request->user)->send(new UserOrdered($order)); //added newly
//Cart::clear();
Session::flash('success', 'Thank you. Your order has been received.');
return redirect()->route('ordersindex');
Problem is:
I get this error
Type error: Argument 1 passed to Illuminate\Mail\PendingMail::send()
must be an instance of Illuminate\Mail\Mailable, instance of
App\Events\UserOrdered given
refers to: Mail::to($event->order->buyer_email)->send(new UserOrdered($event->order));
if I change $event->order at the end of that to something static like $event I will get:
Type error: Argument 1 passed to App\Events\UserOrdered::__construct()
must be an instance of App\Order, instance of App\Events\UserOrdered
given
any idea?