Sunday, April 9, 2017

Expected response code 220 but got code “” with message “”

Leave a Comment

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 MAIL_USERNAME=username@gmail.com 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', 'hello@example.com'),         '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('username@gmail.com');       $message->subject($data['subject']);     });   } 

2 Answers

Answers 1

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 example@gmail.com you should define your MAIL_FROM_ADDRESS (or of course $mail->from()) as example@gmail.com.

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

Answers 2

Similar problem 587 port

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=username@gmail.com MAIL_PASSWORD=mypassword 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment