简体   繁体   中英

cURL error 60: SSL cert issue when sending email with artisan command

I have a weird issue going on with sending emails in Laravel.

I use Mailgun and can send emails fine when users register and everything like that.

I'm beginning to play around with scheduling commands and have created a custom artisan command to get some records and send some emails for these.

However when I run this command I get an error:

cURL error 60: SSL certificate problem: unable to get local issuer certificate

I have set up a cacert.pem locally and linked this successfully in my php.ini file which is how I am able to send emails normally.

I don't understand why my command cannot send emails when I can send them just fine inside a controller.

This is the code I am using for the command:

$reminders = Reminder::where('utcReminderDate' , '<=', \Carbon\Carbon::now()->format('Y-m-d H:i'))->get();

foreach($reminders as $reminder)
    {
        Mail::send('emails.test', [], function($message) {
            $message->to('me@example.com', 'Joe Bloggs');
            $message->subject('A reminder for you');
        });
    }

I'm wanting to get all the reminders that need to be sent and loop through them to send them out.

When I run the command to test it via command line, it spits out the error above.

Any help getting the emails to send would be hugely appreciated. I use WAMP if that makes a difference.

Apparently PHP may load a different php.ini file when it is accessed from the CLI. See here .

Copying my php.ini file into C:\\windows solved the issue.

You can either modify the vendor folder GuzzleHttp\\Client change verify key to false from configureDefaults method as I did in my local machine

or

You can read this conversation in Laracasts and try downloading the .pem files in some of the comments.

Here are some links:

After that you should edit your php.ini file accordingly:

curl.cainfo = "[pathtothisfile]\cacert.pem"

PS: I would just edit the vendor file, because it's much faster and not hard to realize.

Use this code:

$this->client = new GuzzleClient(['defaults' => [
    'verify' => false
]]);

This works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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