Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Khudadad's avatar

Sending email problem

I have a contact form and now I'm working on local computer (localhost) when I hit submit btn I get bellow error.

RequestException in CurlFactory.php line 187:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

This is my method in controller:

public function mailContact(ContactRequest $request)
    {
        $name = $request->input('name');
        $email = $request->input('email');
        $body = $request->input('body');
        $sent = Mail::send('emails.contact', compact('name', 'email', 'body'), function ($message) {
            $message->to('khudadadrs@gmail.com', 'Admin')->subject('Message');
        });

        if ($sent) {
         return Redirect::back()->withMessage('تشکر از اینکه تماس گرفتید.');
     }

        return Redirect::back()->withError('متاسفانه ایمیل ارسال نشد.دوباره تلاش کنید');
    }

.env file

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=oEontENjBIdIrzaXhk9v9Q

config/mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),

/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| settings of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/

'port' => env('MAIL_PORT', 587),

/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/

'from' => ['address' => env('MAIL_USERNAME'), 'name' => env('MAIL_NAME')],

/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/

'encryption' => env('MAIL_ENCRYPTION', 'tls'),

/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/

'username' => env('MAIL_USERNAME'),

/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/

'password' => env('MAIL_PASSWORD'),

/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/

'sendmail' => '/usr/sbin/sendmail -bs',

/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/

'pretend' => false,

];

any help thanks

0 likes
15 replies
lindstrom's avatar

As answered here previously by @Sven0188 :

I had the exact same but on Windows & xampp. My solution was as simple as: Follow this link: ~~http://curl.haxx.se/ca/cacert.pem~~ Copy the entire page and save it in a: "cacert.pem"

Then in your php.ini file insert or edit the following line: curl.cainfo = "[pathtothisfile]\cacert.pem"

Edit: As noted in downthread response, I forgot that there is an issue with that file. Here is a direct link to a working file: https://gist.github.com/VersatilityWerks/5719158/download

lindstrom's avatar

For Xampp on Windows, I put it here (this is my php.ini entry)

[curl]
curl.cainfo=D:\xampp\php\extras\ssl\cacert.pem
Khudadad's avatar

Now a new error, sorry to ask again but this is my first time that I use Laravel mailing.

RequestException in CurlFactory.php line 187:
cURL error 77: error setting certificate verify locations:
CAfile: [pathtothisfile]\cacert.pem
CApath: none (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Khudadad's avatar

No matter bro. Unfortunately this time the same error. when I change the mail driver to smtp and mail host to smtp.gmail.com I'm getting still the same. I'm really confused. any help

Khudadad's avatar

Is there problem with localhost or something else. Of course I'm using wampserver I've installed guzzle http library. If anybody knows? please share

usman's avatar

@Khudadad mr remove your email credentials.

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
......

I mean seriously? better change your password now.

Usman.

2 likes
Khudadad's avatar

Thanks Usman, I forgot it. so, about the error, I have decided to remove / uninstall guzzle, how to do this and want to send email through gmail.

usman's avatar

@Khudadad first make the following changes in your .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@mailservice.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls

After saving the file sign-in to your gmail account, then:

  • From top-right menu select -> My Account
  • Then from main screen select -> sign-in and security
  • Then from left side bar select -> connected apps and sites
  • Then at the bottom check the -> Allow less secure apps (from off to on).

Usman.

bashy's avatar

You need to have DNS setup properly for certification download. If not, supply your own in your OS.

Khudadad's avatar

Thanks @bashy for the reply, but could you make it clearer I'm using windows on my laptop (I work on localhost) thanks

lindstrom's avatar

Did you restart your WAMP? Seems obvious, but you never know. The path I gave way above is literally a copy/paste from my XAMPP php.ini file. Assuming the pem file you downloaded is good and the path you specified in your php.ini is correct, it should work fine for you. You'll just need to provide the full file path on your system. If there is a space in a folder name, be sure to quote the entire path or store it in a directory that doesn't have spaces (only because I can't test that to ensure quoting works).

And just a gentle suggestion, moe to Homestead or ScotchBox 2.5 for you local dev. For all the time you spent debugging this issue, you could have gotten up and running on a VM that would more closely resemble the system where you will eventually deploy your code. I hung onto XAMPP for too long before finally making the switch. Best decision ever. But, you do you--whatever suits you best.

Sorry I'm late to the party and hope you have it sorted!

1 like

Please or to participate in this conversation.