Laravel 邮件通过 smtp 服务器发送错误 503 5.5.2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53703883/
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
Laravel mail sending through smtp server error 503 5.5.2
提问by Miro Hascic
I am trying to send notification mails from php through mail queue in laravel, as far as i can tell everything works fine, i have already tested configuration on my personal mail acc. but when i try sending mail through smtp server it fails with following error.
我正在尝试通过 Laravel 中的邮件队列从 php 发送通知邮件,据我所知一切正常,我已经在我的个人邮件 acc 上测试了配置。但是当我尝试通过 smtp 服务器发送邮件时,它失败并出现以下错误。
mail config in env. :
环境中的邮件配置。:
MAIL_DRIVER=smtp
MAIL_HOST= smtp.server.address
MAIL_PORT=25
mail config in mail.php :
mail.php 中的邮件配置:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mailrelay.vaillant.vhgroup.lan'),
'port' => env('MAIL_PORT', 25),
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'pretend' => env('MAIL_PRETEND', false),
payload:
有效载荷:
{"displayName":"cts\Mail\UnplanedNotification","job":"Illuminate\Queue\CallQueuedHandler@call","maxTries":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"Illuminate\Mail\SendQueuedMailable","command":"O:34:\"Illuminate\Mail\SendQueuedMailable\":3:{s:8:\"mailable\";O:29:\"cts\Mail\UnplanedNotification\":22:{s:9:\"\u0000*\u0000rework\";a:21:{s:12:\"complaint_id\";i:4184;}}}s:6:\"locale\";N;s:4:\"from\";a:0:{}s:2:\"to\";a:1:{i:0;a:2:{s:4:\"name\";N;s:7:\"address\";s:20:\"[email protected]\";}}s:2:\"cc\";a:0:{}s:3:\"bcc\";a:0:{}s:7:\"replyTo\";a:0:{}s:7:\"subject\";N;s:11:\"\u0000*\u0000markdown\";N;s:7:\"\u0000*\u0000html\";N;s:4:\"view\";N;s:8:\"textView\";N;s:8:\"viewData\";a:0:{}s:11:\"attachments\";a:0:{}s:14:\"rawAttachments\";a:0:{}s:9:\"callbacks\";a:0:{}s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:7:\"chained\";a:0:{}}s:5:\"tries\";N;s:7:\"timeout\";N;}"}}
Stacktrace:
堆栈跟踪:
Swift_TransportException: Expected response code 354 but got code "503", with message "503 5.5.2 Need rcpt command
" in /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457
Stack trace:
#0 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(341): Swift_Transport_AbstractSmtpTransport->assertResponseCode('503 5.5.2 Need ...', Array)
#1 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(305): Swift_Transport_AbstractSmtpTransport->executeCommand('DATA\r\n', Array, Array, false, NULL)
#2 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(390): Swift_Transport_EsmtpTransport->executeCommand('DATA\r\n', Array, Array)
#3 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(497): Swift_Transport_AbstractSmtpTransport->doDataCommand(Array)
#4 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(516): Swift_Transport_AbstractSmtpTransport->doMailTransaction(Object(Swift_Message), 'deamon_do_not_r...', Array, Array)
#5 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(206): Swift_Transport_AbstractSmtpTransport->sendTo(Object(Swift_Message), 'deamon_do_not_r...', Array, Array)
#6 /var/www/ctstest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(71): Swift_Transport_AbstractSmtpTransport->send(Object(Swift_Message), Array)
#7 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(464): Swift_Mailer->send(Object(Swift_Message), Array)
#8 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(248): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#9 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(148): Illuminate\Mail\Mailer->send('emails.unplanne...', Array, Object(Closure))
#10 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(18): Illuminate\Mail\Mailable->Illuminate\Mail\{closure}()
#11 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(149): Illuminate\Mail\Mailable->withLocale(NULL, Object(Illuminate\Translation\Translator), Object(Closure))
#12 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php(52): Illuminate\Mail\Mailable->send(Object(Illuminate\Mail\Mailer))
#13 [internal function]: Illuminate\Mail\SendQueuedMailable->handle(Object(Illuminate\Mail\Mailer))
#14 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#15 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#17 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#18 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#19 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Mail\SendQueuedMailable))
#20 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Mail\SendQueuedMailable))
#21 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Mail\SendQueuedMailable), false)
#23 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#24 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#25 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#26 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#27 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#28 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#29 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#30 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#31 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#32 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#33 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#34 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Console/Command.php(179): Illuminate\Container\Container->call(Array)
#35 /var/www/ctstest/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#36 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Console/Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /var/www/ctstest/vendor/symfony/console/Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /var/www/ctstest/vendor/symfony/console/Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/ctstest/vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /var/www/ctstest/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /var/www/ctstest/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 {main}
回答by Manojkiran.A
i had the same issue long time but i have fixed it
我有同样的问题很长时间,但我已经解决了
While you are in the local serve ie) xampp or wampp etc
当您在本地服务时,即)xampp 或 wampp 等
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
but when you are going in live server
但是当你进入实时服务器时
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
Just Change the mail driver to sendmail
I have no idea how its is working but it fixed my server-error-503
只需将邮件驱动程序更改为sendmail
我不知道它是如何工作的,但它修复了我的server-error-503
回答by Ziomikii
This is the .env config file:
这是 .env 配置文件:
MAIL_DRIVER=smtp
MAIL_HOST= smtp.server.address
MAIL_PORT=25
MAIL_USERNAME=Your smtp username (if exists)
MAIL_PASSWORD=Your smtp password (if exists)
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=your email smtp address
MAIL_FROM_NAME=your name
But you should check the correctly params of your smpt server. I can help you if you want.
但是您应该检查 smpt 服务器的正确参数。如果你愿意,我可以帮你。
回答by Adedoyin Akande
If you send a mail from a hostname same as the EMAIL_USERNAME in you .env and the mail doesn't exist in your host server. You get that error. i.e
如果您从与 .env 中的 EMAIL_USERNAME 相同的主机名发送邮件,并且该邮件在您的主机服务器中不存在。你得到那个错误。IE
If EMAIL_USERNAME: [email protected]then mail_from is something like this ->from('[email protected]')and [email protected] doesn't exist.
如果 EMAIL_USERNAME: [email protected]那么 mail_from 是这样的->from('[email protected]')并且 [email protected] 不存在。
In Summary
总之
To send emails from a mail address like "[email protected]" or any mail at all; it is important that you have created that mail on your server or cpanel else it throws the error: "503-All RCPT commands were rejected with this error: 503-Sender verify failed 503 Valid RCPT command must precede DATA"
从“[email protected]”等邮件地址或任何邮件发送电子邮件;重要的是您已经在您的服务器或 cpanel 上创建了该邮件,否则它会抛出错误:“503-所有 RCPT 命令都被拒绝并出现此错误:503-发件人验证失败 503 有效的 RCPT 命令必须在数据之前”
回答by Talha F.
The three most common causes of this error are:
此错误的三个最常见原因是:
- Your email server requires you to check email first before sending email. (Checking email first is one way your email provider manages the security of your email account.)
- Some email provider also check the sender address also, if sender email address doesn't exist then you will get a 503 error.
- Your email client isn't set up for SMTP Authentication.
- 您的电子邮件服务器要求您在发送电子邮件之前先检查电子邮件。(首先检查电子邮件是您的电子邮件提供商管理您的电子邮件帐户安全的一种方式。)
- 一些电子邮件提供商也会检查发件人地址,如果发件人电子邮件地址不存在,那么您将收到 503 错误。
- 您的电子邮件客户端未设置 SMTP 身份验证。
More often, Error 503 tells you that you need to set up SMTP Authentication in your email client.
更常见的是,错误 503 告诉您需要在电子邮件客户端中设置 SMTP 身份验证。
In Laravel you can catch this error and can show an error message like this,
在 Laravel 中,您可以捕获此错误并显示这样的错误消息,
try {
Mail::send('emails.contact-message', [
'msg' => $request->body,
'name' => $request->name,
'email' => $request->email,
],
function ($mail) use($request) {
$mail->from($request->email, $request->name);
$mail->to('[email protected]')->subject('Contact Message');
}
);
// Catch the error
} catch(\Swift_TransportException $e){
if($e->getMessage()) {
dd($e->getMessage());
}
}
回答by Ahmad
I faced same issue, and solved it by changing the port.
我遇到了同样的问题,并通过更改端口解决了它。
If you are using SSLor TLS, Use 587as port instead of 25.
如果您使用SSL或TLS,请使用587而不是 25 作为端口。
hope help.
希望有所帮助。
回答by Jay Suchak
put the configuration details in .env file
将配置细节放在 .env 文件中
ex.
前任。
MAIL_DRIVER=smtp
MAIL_HOST=smtp.server.address
MAIL_PORT=465
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
then restart artisan and test
然后重启工匠并测试
回答by Rouhollah Mazarei
Change this line in .env
file:
更改.env
文件中的这一行:
MAIL_HOST= smtp.server.address
to:
到:
MAIL_HOST= mailrelay.vaillant.vhgroup.lan