Laravel SMTP Email

限于喜欢 提交于 2019-12-22 08:41:22

问题


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' => 'sample_address@gmail.com', 'name' => 'Sample'),
    'encryption' => 'tls',
    'username' => 'sample_address@gmail.com',
    '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('sample_address@gmail.com', 'Laravel Admin');
   $msg->to('sample_receiver@gmail.com');
});

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!


回答1:


you can put your email and name in Input

Input::merge(array('email'=>'sample_receiver@gmail.com','name'=>'sample_name')); 

Mail::send('emails.welcome', 'Laravel Admin', function($msg) {
   $msg->from('sample_address@gmail.com', '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' => 'sample_address@gmail.com', 'name' => 'Sample'),
    'encryption' => 'ssl',
    'username' => 'sample_address@gmail.com',
    'password' => 'sample password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
);



回答2:


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




回答3:


When you are having problems with sending mails via gmail, try this. It worked for me.

Login with your gmail account and then go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha

and click continue. Then, you have few minutes to send your mail with your code. After this, Google will allow sign in to that account from the new source.



来源:https://stackoverflow.com/questions/24709988/laravel-smtp-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!