Laravel 5: Sending Email

29,432

Solution 1

Well, I got it. Infact the email was not authenticated because that email required a mobile phone authentication after login. changing to other email address that required just login credentials, it worked.

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

Solution 2

GMail SMTP requires encryption. Try changing setting as following.

 MAIL_PORT=465
 MAIL_ENCRYPTION=ssl

Solution 3

I made the following mistake: I did not actually include the

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

to the array return in mail.php. I did include my host, port, username and password in the mail.php but not the encryption method (the encryption method I only included in the .env file), so trying out these mentioned solutions did bring a change in the error messages outcome, created a bigger confusion, but none solved the problem. Hope this helps someone!

Share:
29,432
Saani
Author by

Saani

A versatile and professional web application developer with a commitment to develop & work with innovative & creative web solutions.

Updated on January 25, 2020

Comments

  • Saani
    Saani over 4 years

    I am trying to send an email in laravel application. Here is my .env file:

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

    And here is the Mail::send method:

    Mail::send('email', ['name' => "EE"], function($m){
                $m->to('[email protected]', 'Malik')->subject('Subjet of the email');
            });
    

    And here is the error:

    Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp"
    

    Any help?

    • Tarunn
      Tarunn almost 9 years
      where are you using this code, local or server?
    • Saani
      Saani almost 9 years
      If u mean the Mail::send(---) code, then i m using it in Controller.
    • Tarunn
      Tarunn almost 9 years
      I mean... u r on localhost or Server!?
    • Ash
      Ash almost 9 years
      It's just an authentication error. I would suggest following the instructions of the error message 530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp.
    • Ash
      Ash almost 9 years
      A quick google get's this... richardwillia.ms/blog/2010/12/swift-mailer-starttls - I hope it helps
    • Saani
      Saani almost 9 years
      yeah, i m on localhost..
    • Saani
      Saani almost 9 years
      I am not using swift mailer @Ash, I am using laravel, so how to deal with starttls problem in laravel, any idea?
    • Ash
      Ash almost 9 years
      Laravel uses Swift mailer which is also a Symfony component.
  • Saani
    Saani almost 9 years
    tried with no benefit, giving the error: Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. w8sm20719292wja.15 - gsmtp "
  • Tarunn
    Tarunn almost 9 years
    what is your driver settings 'driver' => env('MAIL_DRIVER', 'smtp') in mail config??
  • Saani
    Saani almost 9 years
    This is the driver settings: 'driver' => env('MAIL_DRIVER', 'smtp')
  • Saani
    Saani almost 9 years
    This is host: 'host' => env('MAIL_HOST', 'smtp.gmail.com') and this is port: 'port' => env('MAIL_PORT', 465) in mail config file
  • Tarunn
    Tarunn almost 9 years
    other settings like driver, port, host in config??
  • Ash
    Ash almost 9 years
    your .env file MAIL_HOST should be this: MAIL_HOST=smtp.gmail.com. The env() function will attempt to load a variable from the .env or use the default: env('KEY', 'the default'). (this is for someone who comes here with the same issue)
  • Dov Benyomin Sohacheski
    Dov Benyomin Sohacheski over 6 years
    Is this a suggestion or an answer?