Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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']);
    });
  }
like image 389
user968270 Avatar asked Mar 13 '17 18:03

user968270


2 Answers

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).

like image 127
Uğur Arıcı Avatar answered Sep 30 '22 17:09

Uğur Arıcı


Similar problem 587 port

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
like image 39
Takamura Avatar answered Sep 30 '22 19:09

Takamura