【问题标题】:Laravel 5.1 sending email error : stream_set_blocking() expects parameter 1 to be resource, null givenLaravel 5.1 发送电子邮件错误:stream_set_blocking() 期望参数 1 是资源,给定 null
【发布时间】:2016-07-07 00:51:07
【问题描述】:

我正在使用 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 中)测试这个项目时,我工作得很好并且可以发送电子邮件!

但是当我想在服务器(在线)中使用它时,我会更改我的 .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/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php', '275', array('host' => 'localhost', 'timeout' => '30', 'options' => array(), 'streamContext' => 资源, 'errno' => null, 'errstr' => null)) 在 StreamBuffer.php 第 275 行的 stream_set_blocking(null, '1') 在 Swift_Transport_StreamBuffer->_establishSocketConnection() 中 StreamBuffer.php 第 62 行 Swift_Transport_StreamBuffer->initialize(array('protocol' => null, 'host' => 'localhost', 'port' => '587', 'timeout' => '30', '阻塞' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) 在 AbstractSmtpTransport.php 第 113 行 Mailer.php 第 79 行中的 Swift_Transport_AbstractSmtpTransport->start() 在 Mailer.php 中的 Swift_Mailer->send(object(Swift_Message), array()) Mailer->sendSwiftMessage(object(Swift_Message)) 的第 395 行 Mailer.php 第 181 行 Mailer->send('emails.simple', array(), Facade.php 第 222 行中的 object(Closure)) Facade::__callStatic('send', array('emails.simple', array(), 对象(闭包)))在 CallbackController.php 第 114 行 Mail::send('emails.simple', array(), object(Closure)) in CallbackController.php 第 114 行 CallbackController->getEm()

【问题讨论】:

  • 尝试检查您的主机是否启用了“proc_open”功能,例如用这个小sn-p:<?php echo function_exists('proc_open') ? "Yep, that will work" : "Sorry, that won't work"; ?>

标签: php email laravel laravel-5.1 swiftmailer


【解决方案1】:

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

  1. 云虚拟机环境不支持stream_socket_client功能。
  2. 只要把他改成fsockopen函数。端口是465 ssl,因为25被禁止了。类似于$this->stream = @fsockopen($host, $this->params['port'], $errno, $errstr, $timeout)
  3. 在云虚拟机后台打开 fsockopen 函数。

我的英语不是很好,对不起。

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 1970-01-01
    • 2021-01-02
    • 2016-11-15
    • 2021-12-17
    • 2016-10-26
    • 1970-01-01
    • 2016-08-09
    • 2018-09-28
    相关资源
    最近更新 更多