Hello.
In my app I have a form which allow the user to choose/insert: date/time, list of emails and text/subject of message. This is used to send emails.
The text/subject is inserted in the table CONVITE (cod_convite, subject, body).
The email and date/time are inserted in the table FILA (cod_fila, email, date, cod_convite).
Crons that run every minute are configured in the server.
I have this command to handle the table FILA. The emails are send using MANDRILL.
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class FilaCommand extends Command {
protected $name = 'fila:disparar';
protected $description = 'Something here.';
public function fire() {
// Looking for messages that should be send
$agendados = Fila::where('date', '>=', 'CURDATE()')
->orderBy('cod_fila', 'asc')
->get();
foreach ($agendados as $a) {
$convite = Convite::where('cod_convite', '=', $a['cod_convite'])->first();
// Send
Mail::send('emails.sample', array($convite['body']), function($message) {
$message->from('sistema@teste.com', 'Test System');
$message->to($a['email']);
$message->subject($convite['subject']);
});
// Delete
$fila_item = Fila::find($a['cod_fila']);
$fila_item->delete();
}
}
}
About my code, I have the following questions:
Can this be done faster? Can my tables be improved?
Should I limit the emails sent for call, grouping them, or this is desnecessary?
Should I use mail:send or mail:queue?
How can I track the number of emails already sent to show in a page in the app?
How can I cancel a send?
Its possible to get and store in the database the result of 'mandrill send'?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community