user968270
user968270

Reputation: 4971

Expected response code 220 but got code "" with message ""

Every time I submit the contact form on my Laravel application I receive the error message in the title. I've followed the recommendation in this discussion, but it has had no effect even after php artisan cache:clear and php artisan config:cache. Here's the relevant code:

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

config/mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),    
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

I was under the impression from the documentation that the global 'from' wouldn't fire unless no other from address was provided, but in my controller for the mail, I specified the address supplied to the contact form as the 'from,' is that a conflict point somehow? It doesn't seem to be from the error message details.

Because the contact form is not a distinct view but the bottom of the mainpage view, the Controller function lives in PageController

public function postContact(Request $request) {
    $this->validate($request, [

      'email' => 'required|email',
      'subject' => 'required|min:3',
      'message' => 'required|min:10'
    ]);

    $data = array(
      'email' => $request->email,
      'subject' => $request->subject,
      'mailbody' => $request->message
    );

    Mail::send('emails.contact', $data, function($message) use ($data) {
      $message->from($data['email']);
      $message->to('[email protected]');
      $message->subject($data['subject']);
    });
  }

Upvotes: 10

Views: 16027

Answers (4)

Pyuri Sahu
Pyuri Sahu

Reputation: 449

I was getting the same error.. It is working fine when i changed EMAIL_ENCRYPTION It was 'encryption' => env('MAIL_ENCRYPTION', 'tps'), before I change it to 'encryption' => env('MAIL_ENCRYPTION', ''),

Upvotes: 0

sparsh turkane
sparsh turkane

Reputation: 1323

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=secreat
MAIL_ENCRYPTION=ssl

Update above code in Your .env file and then run these commands in terminal

  1. composer dump-autoload

  2. php artisan serve

Upvotes: 0

Uğur Arıcı
Uğur Arıcı

Reputation: 1280

I think you should define mail sender (MAIL_FROM_ADDRESS) as your gmail which you want to use send emails with.

for example, if your MAIL_USERNAME at .env is [email protected] you should define your MAIL_FROM_ADDRESS (or of course $mail->from()) as [email protected].

I don't think gmail allows you send emails as another user (another address).

Upvotes: 6

Takamura
Takamura

Reputation: 312

Similar problem 587 port

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

Upvotes: 1

Related Questions