laravel 预期响应代码 220 但得到代码“”和消息“”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42770725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected response code 220 but got code "" with message ""
提问by user968270
Every time I submit the contact form on my Laravel application I receive the error message in the title. I've followed the recommendation in this discussion, but it has had no effect even after php artisan cache:clear
and php artisan config:cache
. Here's the relevant code:
每次我在 Laravel 应用程序上提交联系表单时,我都会收到标题中的错误消息。我遵循了本次讨论中的建议,但即使在php artisan cache:clear
和之后也没有效果php artisan config:cache
。这是相关的代码:
.env
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
config/mail.php
配置/mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I was under the impression from the documentation that the global 'from' wouldn't fire unless no other from address was provided, but in my controller for the mail, I specified the address supplied to the contact form as the 'from,' is that a conflict point somehow? It doesn't seem to be from the error message details.
文档给我的印象是,除非没有提供其他发件人地址,否则全局“发件人”不会触发,但是在我的邮件控制器中,我将提供给联系表单的地址指定为“发件人”,是不知何故,一个冲突点?它似乎不是来自错误消息的详细信息。
Because the contact form is not a distinct view but the bottom of the mainpage view, the Controller function lives in PageController
因为联系表单不是一个独特的视图,而是主页视图的底部,Controller 函数位于PageController 中
public function postContact(Request $request) {
$this->validate($request, [
'email' => 'required|email',
'subject' => 'required|min:3',
'message' => 'required|min:10'
]);
$data = array(
'email' => $request->email,
'subject' => $request->subject,
'mailbody' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('[email protected]');
$message->subject($data['subject']);
});
}
回答by U?ur Ar?c?
I think you should define mail sender (MAIL_FROM_ADDRESS
) as your gmail which you want to use send emails with.
我认为您应该将邮件发件人 ( MAIL_FROM_ADDRESS
)定义为您要用于发送电子邮件的 gmail。
for example, if your MAIL_USERNAME
at .env
is [email protected]you should define your MAIL_FROM_ADDRESS
(or of course $mail->from()
) as [email protected].
例如,如果您的MAIL_USERNAME
at.env
是[email protected]您应该将您的MAIL_FROM_ADDRESS
(或当然$mail->from()
)定义为[email protected]。
I don't think gmail allows you send emails as another user (another address).
我认为 gmail 不允许您以另一个用户(另一个地址)的身份发送电子邮件。
回答by Takamura
Similar problem587 port
587端口类似问题
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
回答by sparsh turkane
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=secreat
MAIL_ENCRYPTION=ssl
Update above code in Your .env file and then run these commands in terminal
在你的 .env 文件中更新上面的代码,然后在终端中运行这些命令
composer dump-autoload
php artisan serve
composer dump-autoload
php artisan serve
回答by Pyuri Sahu
I was getting the same error.. It is working fine when i changed EMAIL_ENCRYPTION
It was 'encryption' => env('MAIL_ENCRYPTION', 'tps'),
before
I change it to 'encryption' => env('MAIL_ENCRYPTION', ''),
我遇到了同样的错误..当我更改 EMAIL_ENCRYPTION 时它工作正常 这是'encryption' => env('MAIL_ENCRYPTION', 'tps'),
在我将其更改为之前'encryption' => env('MAIL_ENCRYPTION', ''),