Laravel 5.1 sending email error : stream_set_blocking() expects parameter 1 to be resource, null given
我正在使用Laravel 5.1,我想发送电子邮件(smtp)
这是我的
1 2 3 4 5 6 | MAIL_DRIVER=smtp MAIL_HOST=mail.mydomain.ir MAIL_PORT=587 MAIL_USERNAME=account@mydomain.ir MAIL_PASSWORD= .... MAIL_ENCRYPTION=null |
这在
1 |
和一个测试功能,用于发送简单的测试电子邮件:
1 2 3 4 5 6 7 8 | public function getEm() { $input = [] ; Mail::send('emails.simple', $input, function($message) { $message->to('[email protected]', 'Learning')->subject('Contact view Our Contact Form'); }); return 'Your message has been sent'; } |
当我在localhost(在WampServer中)测试此项目时,我运行良好并发送电子邮件ok!
但是,当我想在服务器(在线)中使用它时,我将更改
1 2 3 4 5 6 | MAIL_DRIVER=smtp MAIL_HOST=localhost MAIL_PORT=587 MAIL_USERNAME=account@mydomain.ir MAIL_PASSWORD=.... MAIL_ENCRYPTION=null |
我看到这个错误:
ErrorException in StreamBuffer.php line 275:
stream_set_blocking() expects parameter 1 to be resource, null given
in StreamBuffer.php line 275 at HandleExceptions->handleError('2',
'stream_set_blocking() expects parameter 1 to be resource, null
given',
'/home2/net45987/domains/esetn32.ir/public_html/la/user/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php',
'275', array('host' => 'localhost', 'timeout' => '30', 'options' =>
array(), 'streamContext' => resource, 'errno' => null, 'errstr' =>
null)) at stream_set_blocking(null, '1') in StreamBuffer.php line 275
at Swift_Transport_StreamBuffer->_establishSocketConnection() in
StreamBuffer.php line 62 at
Swift_Transport_StreamBuffer->initialize(array('protocol' => null,
'host' => 'localhost', 'port' => '587', 'timeout' => '30', 'blocking'
=> '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113 at
Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php
line 395 at Mailer->sendSwiftMessage(object(Swift_Message)) in
Mailer.php line 181 at Mailer->send('emails.simple', array(),
object(Closure)) in Facade.php line 222 at
Facade::__callStatic('send', array('emails.simple', array(),
object(Closure))) in CallbackController.php line 114 at
Mail::send('emails.simple', array(), object(Closure)) in
CallbackController.php line 114 at CallbackController->getEm()
您解决这个问题这么久了吗?我最近也遇到过同样的问题。解决方案是:
对不起,我的英语不太好。