1
I’m trying to get my system from a cronjob, send email to a certain list, my problem is this: when I do it through a route have no problem any emails are sent!
But when sending the email is done through a function call that runs in cronjob the email is not sent, so I tried to do as it is recommended on the web to create a Queue that will send. I managed to make What works perfectly, it reaches the function of sending email, but the email is not sent and has no error message!
Note: The email is sent if I access a get route defined by me.
Follow the code for analysis:
class Sendmailjob Mplements Shouldqueue
class SendMailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $lead;
protected $item;
protected $campaignLeadId;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($lead, $item, $campaignLeadId)
{
$this->lead = $lead;
$this->item = $item;
$this->campaignLeadId = $campaignLeadId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$item = $this->item;
$lead = $this->lead;
$campaignLeadId = $this->campaignLeadId;
Mail::queue(new DefaultMail($lead,$item,$campaignLeadId));
}
}
class Defaultmail
class DefaultMail extends Mailable
{
use Queueable, SerializesModels;
public $template;
protected $id;
public $subject;
public $lead;
public $item;
public $campaignLeadId;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($lead, $item, $campaignLeadId)
{
$this->lead = $lead ;
$this->item = $item;
$this->campaignLeadId =$campaignLeadId;
}
/**
* Build the message.
*
* @return $this
*/
public function build(Mailable $mailable)
{
$url = 'https://***********.com';//env('APP_ENV')!='local'?'https://***********.com/':'http://agencia.test';
$template = $this->item['template'];
$template = str_replace("[[NOME]]", $this->lead['name'], $template);
$template = str_replace("[[LINK]]", $url.'/u/'.$this->campaignLeadId, $template);
$template = str_replace("[[LINK_OPT-OUT]]", $url.'/u/out/'.$this->campaignLeadId, $template);
$lead = $this->lead ;
$item = $this->item;
$campaignLeadId =$this->campaignLeadId;
return $this->to($lead['email'], $lead['name'])->from('***********@***********.com','Everton da Ilha do Software')
->html($template)->subject($item['name'])->view('template.renderMail', ['template' => $template]);
}
}
class Sendmailscron JOB call
if(dispatch(new SendMailJob($lead, $item, $campaignLeadId))){
DB::commit();
$sendCount++;
}
managed to solve ?
– Bulfaitelo
with the functionality developed by the Lockable no, I had to use phpmailer. I developed a function within the job with this library, ai the sending worked!
– Lodi