0
votes

I am trying to sent an email using laravel 5.6 but I fail.

In my .env file I put my private gmail, so that all mails are sent to this email.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

Further I created a Mailable class like this:

class InquirySent extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

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

    public function build()
    {
        return $this->from($this->data['email'])
                    ->view('emails.contacts.inquiry');
    }
}

I just Need to add this data to the mail which I get from a form:

array:3 [
  "name" => "foo"
  "email" => "[email protected]"
  "phoneNumber" => "16547613247805"
]

In my Controller I have following function to sent the mail:

public function sent(ContactRequest $request)
{
    $data = $request->all();

    Mail::to(env('MAIL_USERNAME'))->send(new InquirySent($data));
}

The error message:

{,…}
exception
:
"ErrorException"
file
:
"D:\laragon\www\tim\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php"
line
:
94
message
:
"stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:↵error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed"
trace
:
[{function: "handleError", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]
3
and where's error message?devnull Ψ
@devnullΨ sorry updated the questiontigerel
Can you try port 465 ?Chris
@Chris using port 465 gives me no error but I do not get an email aswell ?tigerel
did you allow less secure app in your gmail? support.google.com/accounts/answer/6010255?hl=endevnull Ψ

3 Answers

1
votes

In config folder find mail.php file and ADD BELOW CODE.

'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true,
    ],
0
votes

There is no problem with your code. Add some delay and try to use queue. Also tls could be a problem. You can delete it or block ssl permissions.

 Mail::to(env('MAIL_USERNAME'))->send((new InquirySent($data))->delay(30));

and php artisan queue:work

0
votes

In addition to @Cool's answer, for Laravel 5.6 you need to ADD this code to config/mail.php

'stream' => [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true,
    ],
]