Laravel SMTP电子邮件 [英] Laravel SMTP Email

查看:131
本文介绍了Laravel SMTP电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始使用Laravel 4.2,我尝试使用Gmail STMP服务器发送电子邮件.以下是我的app/config/mail.php.

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,
);

下面是我的php代码.

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');
});

但是它不起作用.我已经在我的MAC OSX上配置了XAMPP php.ini.仅在发送普通的PHP邮件而不是SMTP时有效.我在查看页面上从Laravel获得的错误消息是"异常处理程序中的错误".我想查看更多错误信息,但我不知道如何获取更多信息.我的代码有什么问题?我还需要做什么或配置?谢谢!

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!

推荐答案

您可以将您的电子邮件和姓名放在输入"中

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');
});

还更改了加密"

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,
);

这篇关于Laravel SMTP电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆