Search code examples
emaillaravelsmtpgmail

Laravel 4 Mail Connection could not be established with host smtp.gmail.org


I always getting an error when sending an email. I already openned the open_ssl on php.ini . Currently i am using "guzzlehttp/guzzle": "~4.0" for the mail. Here's my mail.php settings :

'driver' => 'smtp',
'host' => 'smtp.gmail.org',
'port' => 587,
'from' => array('address' => '[email protected]', 'name' => 'tonight'),
'encryption' => 'tls',
'username' => '', //i already set the username + pass correctly
'password' => '',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

Mail::send('mail', array('firstname'=>'budi'), function($message) {
    $message->to('[email protected]','lukas aa')->subject('Welcome to the Laravel 4 Auth App!');
});

Solution

  • Use Mandrill driver instead of smtp. Laravel ships with it.

    in app/config/mail.php

    change this line

    'driver' => 'mandrill',
    

    go to https://mandrillapp.com/settings

    sign up and create an an api key

    create an app/config/services.php configuration fileand add below configurations and mandrill api key

    return array(
    
    'mailgun' => array(
        'domain' => '',
        'secret' => '',
    ),
    
    'mandrill' => array(
        'secret' => 'enter your mandrill api key here',
    ),
    
    'stripe' => array(
        'model'  => 'User',
        'secret' => '',
    ),
    
    );