我正在尝试使用来自localhost的Laravel从Gmail发送电子邮件。我收到此错误:无法与主机smtp.gmail.com [#0]建立连接
我正在使用端口465的ssl。我也尝试过587但它没有用。
我也试过this,但它没有用。我发现很多人都遇到了同样的问题,但我找到的解决方案却没有用。
我有同样的错误:无法与主机smtp.gmail.com [#0]建立连接,并按照此处列出的步骤进行:https://github.com/swiftmailer/swiftmailer/issues/544。
尝试在第263行的Swift / Transport / StreamBuffer.php中将以下行添加到_establishSocketConnection()
:
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
请注意,这不是一个完美的解决方案,因为它涉及:a)黑客可能在SwiftMailer更新中覆盖的核心代码,以及b)在您不再验证连接时降低应用程序的安全性。但作为临时解决方案,它对我有用。
在.env文件中,您需要设置电子邮件帐户的电子邮件地址和密码。
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=testpassword
并填写mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Your Title'],
'encryption' => 'tls',
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
并使用此清除配置缓存。
php artisan config:cache
在Laravel项目目录中,编辑config/mail.php
并添加以下内容:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
它对我有用。
Fyi,我的SMTP设置是:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=[Full Gmail Address]
MAIL_PASSWORD=[Google App Password obtained after two step verification on Google Account Page]
MAIL_ENCRYPTION=ssl
您是否尝试将加密更改为tls?我目前使用Gmail SMTP服务器从我的Laravel应用发送电子邮件。我使用TLS和端口587
https://accounts.google.com/DisplayUnlockCaptcha https://www.google.com/settings/security/lesssecureapps
约
MAIL_DRIVER = SMTP
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_PASSWORD =测试
MAIL_ENCRYPTION = tls / ******** /
email.php
'from'=> ['address'=>'[email protected]','name'=>'test'],
经过长时间的搜索,这对我有用,最好的配置:
'driver' => 'smtp',
'host' => 'smtp-mail.outlook.com',
'port' => 587, ( or 25)
'encryption' => 'tls',
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=testpassword
默认情况下,您无法从localhost发送电子邮件。
如果您正确配置文件,您将能够从中发送电子邮件。
您还可以尝试在服务器或生产区域上载站点。在那里它会工作。