简体   繁体   English

Laravel Queue无法通过Curl发送电子邮件

[英]Laravel Queue cant send email via Curl

I am trying to use laravel Queue 我正在尝试使用laravel Queue

I am using the following command to send data to my queue 我正在使用以下命令将数据发送到队列

  $data = array(
        'from'=> $mailfromname .'<'.$mailfrom.'>',
        'to'=>$toname.'<'.$to.'>',
        'subject'=>$subject,
        'html'=>$html,
        'text'=>$text,
        'o:tracking'=>'yes',
        'o:tracking-clicks'=>'yes',
        'o:tracking-opens'=>'yes',
        'o:tag'=>$tag,
        'h:Reply-To'=>$replyto
    );

Than i send the array to my ExampleJob 比我将数组发送到我的ExampleJob

 Queue::push(new ExampleJob($data)); 

I have than in the in the handle of my job a curl function that accepts the $data 我在工作的句柄中有一个可以接受$ data的curl函数

So my problem here is my curl function works fine if i send the emails without using jobs but when i use jobs I see the jobs table being populated and than it processes but no email sends using curl ... anyone know why is that ? 所以我的问题是,如果我不使用作业发送电子邮件,我的curl函数就可以正常工作,但是当我使用作业时,我看到jobs表被填充,然后它进行处理,但是没有使用curl发送电子邮件...有人知道为什么吗?

public function handle($data)
{
     $session = curl_init(MAILGUN_URL.'/messages');
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, 'api:'.MAILGUN_KEY);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($session);
curl_close($session);
$results = json_decode($response, true);
return $results
}

您的handle方法的参数是$data但我只看到正在使用$array_data

you need to set the $data in the constructor of your job, not in the handle function 您需要在作业的构造函数中而不是在handle函数中设置$data

refer to this example https://laravel.com/docs/5.6/queues#class-structure 请参阅此示例https://laravel.com/docs/5.6/queues#class-structure

public function __construct($data) { $this->data = $data; }

我实际上发现了问题,您看到Curl运行缓慢,因此在que中使用curl时,需要确保为其提供足够的运行时间,因此将队列侦听时间设置为60秒。

php artisan queue:listen --timeout=60

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM