Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1发送电子邮件错误:stream_set_blocking()要求参数1为资源,给定为null_Php_Email_Laravel_Laravel 5.1_Swiftmailer - Fatal编程技术网

Php Laravel 5.1发送电子邮件错误:stream_set_blocking()要求参数1为资源,给定为null

Php Laravel 5.1发送电子邮件错误:stream_set_blocking()要求参数1为资源,给定为null,php,email,laravel,laravel-5.1,swiftmailer,Php,Email,Laravel,Laravel 5.1,Swiftmailer,我正在使用Laravel 5.1,我想发送电子邮件(smtp) 这是我的.env配置: MAIL_DRIVER=smtp MAIL_HOST=mail.mydomain.ir MAIL_PORT=587 MAIL_USERNAME=account@mydomain.ir MAIL_PASSWORD= .... MAIL_ENCRYPTION=null 在config/mail.php中: 'from' => ['address' =>env('MAIL_USERNAME', 'ac

我正在使用Laravel 5.1,我想发送电子邮件(smtp) 这是我的
.env
配置:

MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.ir
MAIL_PORT=587
MAIL_USERNAME=account@mydomain.ir
MAIL_PASSWORD= ....
MAIL_ENCRYPTION=null
config/mail.php
中:

'from' => ['address' =>env('MAIL_USERNAME', 'account@mydomain.ir'), 'name' => 'ESET'],
以及发送简单测试电子邮件的测试功能:

public function getEm()
{
    $input = [] ;
    Mail::send('emails.simple', $input, function($message) {
            $message->to('some@gmail.com', 'Learning')->subject('Contact view Our Contact Form');
    });
    return 'Your message has been sent';
}
当我在localhost(在WampServer中)中测试这个项目时,我工作正常,并且发送电子邮件ok

但是,当我想在服务器(联机)中使用它时,我将更改我的
.env
配置,因为我的主机支持会这样说:

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=587
MAIL_USERNAME=account@mydomain.ir
MAIL_PASSWORD=....
MAIL_ENCRYPTION=null
我看到这个错误:

StreamBuffer.php第275行中的ErrorException:

stream_set_blocking()要求参数1为资源,给定null

在StreamBuffer.php第275行的HandleExceptions->handleError('2')中, 'stream_set_blocking()要求参数1为资源,null 给定', “/home2/net45987/domains/esetn32.ir/public_html/la/user/vendor/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php”, '275',数组('host'=>'localhost','timeout'=>'30','options'=> array(),'streamContext'=>resource,'errno'=>null,'errstr'=> 在StreamBuffer.php第275行的stream_set_阻塞(null,'1')处 在Swift_Transport_StreamBuffer->_establishSocketConnection()中 StreamBuffer.php第62行 Swift\u Transport\u StreamBuffer->initialize(数组('protocol'=>null, '主机'=>'本地主机','端口'=>'587','超时'=>'30','阻塞' =>'1','tls'=>false',在AbstractSmtpTransport.php第113行中键入'=>'1','stream\u context\u options'=>array() Mailer.php第79行中的Swift\u Transport\u AbstractSmtpTransport->start() 在Mailer.php中的Swift\u Mailer->send(object(Swift\u Message),array() 第395行中的Mailer->sendSwiftMessage(对象(Swift_Message))处 Mailer->send('emails.simple',array(),Mailer.php第181行, Facade.php第222行中的 Facade::_callStatic('send',array('emails.simple',array(), 对象(闭包)),位于CallbackController.php第114行 邮件::在中发送('emails.simple',array(),object(Closure)) CallbackController->getEm()处的CallbackController.php第114行


你解决这个问题这么久了吗?我最近也遇到了同样的问题。解决方法是:

  • 云虚拟机环境不支持stream_socket_客户端功能
  • 只需将其更改为fsockopen函数。端口是465 ssl,因为25 ssl将被禁止。类似于
    $this->stream=@fsockopen($host,$this->params['port'],$errno,$errstr,$timeout)
  • 在云虚拟机后台打开fsockopen函数
  • 对不起,我的英语不是很好。

    请尝试检查您的主人是否启用了“proc_open”功能,例如,使用以下小片段: