php Laravel SMTP 电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24709988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel SMTP Email
提问by O Connor
Start working with Laravel 4.2 I tried to send email using Gmail STMP server. Below is my app/config/mail.php.
开始使用 Laravel 4.2 我尝试使用 Gmail STMP 服务器发送电子邮件。下面是我的 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.
下面是我的php代码。
<!-- 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!
但它不起作用。我已经在我的 MAC OSX 上配置了我的 XAMPP php.ini。它仅适用于发送普通 PHP 邮件,而不适用于 SMTP。我在视图页面上从 Laravel 获得的错误消息是“异常处理程序中的错误”。我想查看更多错误信息,但我不知道如何获取更多信息。我的代码有什么问题?我还需要做什么或配置什么?谢谢!
回答by gaurangkathiriya
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,
);
回答by DevSwert
You should change 'encryption' for ssl and in your gmail must be enabled IMAP access in config
您应该更改 ssl 的“加密”,并且在您的 gmail 中必须在配置中启用 IMAP 访问
回答by vstruhar
When you are having problems with sending mails via gmail, try this. It worked for me.
当您在通过 gmail 发送邮件时遇到问题时,试试这个。它对我有用。
Login with your gmail account and then go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha
使用您的 Gmail 帐户登录,然后访问: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.
然后点击继续。然后,您有几分钟的时间发送带有代码的邮件。在此之后,Google 将允许从新来源登录该帐户。