Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel SMTP Email

Start working with Laravel 4.2 I tried to send email using Gmail STMP server. Below is my app/config/mail.php.

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'from' => array('address' => '[email protected]', 'name' => 'Sample'),
    'encryption' => 'tls',
    'username' => '[email protected]',
    'password' => 'sample password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
);

Below is my php code.

<!-- app/views/emails/welcome.php -->
Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
   $msg->from('[email protected]', 'Laravel Admin');
   $msg->to('[email protected]');
});

But it does not work. I have already configured my XAMPP php.ini on my MAC OSX. It only works when sending a normal PHP mail, not SMTP. The error message that I've got from Laravel on the view page is 'Error in exception handler'. I would like to see more error information but I don't know how to get more info. What is wrong with my code? What else do I need to do or configure? Thank you!

like image 869
O Connor Avatar asked Mar 19 '23 01:03

O Connor


2 Answers

you can put your email and name in Input

Input::merge(array('email'=>'[email protected]','name'=>'sample_name')); 

Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
   $msg->from('[email protected]', 'Laravel Admin');
   $msg->to(Input::get('email'), Input::get('name'))->subject('You have');
});

also change 'encryption'

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'from' => array('address' => '[email protected]', 'name' => 'Sample'),
    'encryption' => 'ssl',
    'username' => '[email protected]',
    'password' => 'sample password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
);
like image 121
gaurangkathiriya Avatar answered Mar 23 '23 18:03

gaurangkathiriya


You should change 'encryption' for ssl and in your gmail must be enabled IMAP access in config

like image 22
DevSwert Avatar answered Mar 23 '23 18:03

DevSwert