Php stream_set_blocking()要求参数1为资源,给定null
我想用Laravel 5.4从在线服务器发送电子邮件。我不知道问题是出在我的代码还是服务器上。我从easyname.com获得了主机 这是我的.env文件Php stream_set_blocking()要求参数1为资源,给定null,php,laravel,smtp,laravel-5.3,swiftmailer,Php,Laravel,Smtp,Laravel 5.3,Swiftmailer,我想用Laravel 5.4从在线服务器发送电子邮件。我不知道问题是出在我的代码还是服务器上。我从easyname.com获得了主机 这是我的.env文件 MAIL_DRIVER=smtp MAIL_HOST=smtp.easyname.com MAIL_PORT=465 MAIL_USERNAME=info@mydomain.com MAIL_PASSWORD=mypasword MAIL_ENCRYPTION= 这是我的config/mail.php文件 <?php return
MAIL_DRIVER=smtp
MAIL_HOST=smtp.easyname.com
MAIL_PORT=465
MAIL_USERNAME=info@mydomain.com
MAIL_PASSWORD=mypasword
MAIL_ENCRYPTION=
这是我的config/mail.php文件
<?php
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
| "sparkpost", "log", "array"
|
*/
'driver' => env('MAIL_DRIVER', 'smtp'),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.easyname.com'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 465),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info@mydomain.com'),
'name' => env('MAIL_FROM_NAME', 'My Name'),
],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', ''),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
需要一个资源作为其第一个参数。当该资源不存在时,就会发生错误。这可能是因为套接字连接无法成功打开
问题行可能来自AbstractSmtpTransport.php,第113行:
Swift_Transport_StreamBuffer->initialize(
['protocol'=>'', 'host'=>'smtp.easyname.com', 'port'=>465...]
)
我不熟悉这个库,但我打赌它应该返回一个打开的套接字,但它失败了,null
被返回,并且库在stream\u set\u blocking()中使用套接字之前从未检查成功
首先,我要研究为什么协议是空字符串,以及它应该是什么。我通过在.env文件和MAIL.php文件中将MAIL\u驱动程序从MAIL\u DRIVER=smtp
更改为MAIL\u DRIVER=MAIL
解决了这个问题。还要将邮件加密从MAIL\u ENCRYPTION=
更改为MAIL\u ENCRYPTION=ssl
若要解决此问题,请尝试:
云虚拟机环境不支持stream\u socket\u client
功能
只需将其更改为fsockopen函数。端口是465SSL,因为25个端口将被禁止。类似于$this->stream=@fsockopen($host,$this->params['port'],$errno,$errstr,$timeout)
在云虚拟机后台打开fsockopen函数