在共享主机上使用 Laravel 发送邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47291048/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:58:07  来源:igfitidea点击:

Sending mail with Laravel on shared hosting

phplaravelemaillaravel-5.5

提问by Rubberduck1337106092

I'm trying to send mail from my website.

我正在尝试从我的网站发送邮件。

I'm using laravel 5.5 and the shared hosting of hostnet.nl.

我正在使用 laravel 5.5 和 hostnet.nl 的共享主机。

I'm very sure i have all my configuration correct..

我很确定我的所有配置都是正确的..

My .env :

我的 .env :

MAIL_DRIVER=mail
MAIL_HOST=smtp02.hostnet.nl
MAIL_PORT=587
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=TLS

But when i try to send mail this allways returns

但是当我尝试发送邮件时,这总是会返回

Whoops there was an error:

哎呀有一个错误:

proc_open() has been disabled for security reasons I already chat with the hosting company and they said this is not a php setting that is allowed to be changed. So i cannot enable this.

proc_open() has been disabled for security reasons 我已经与托管公司聊天,他们说这不是一个允许更改的 php 设置。所以我无法启用它。

When i try to set MAIL_DRIVER=smtpit says connection refused.

当我尝试设置时,MAIL_DRIVER=smtp它说连接被拒绝。

I have another laravel installation/website at this shared hosting, which has the same MAIL_DRIVER=mailand this works perfectly.

我在这个共享主机上有另一个 Laravel 安装/网站,它具有相同的功能,MAIL_DRIVER=mail并且运行良好。

This installation is on laravel 5.2.*

此安装在 Laravel 5.2.* 上

Is this something that has changed inside swiftmailer from laravel 5.2 to 5.5?

这是否在 swiftmailer 内部从 laravel 5.2 到 5.5 发生了变化?

I don't know how to fix this issue.

我不知道如何解决这个问题。

Any help is appreciated.

任何帮助表示赞赏。

回答by Kristian Lilov

You should try changing this :

你应该尝试改变这个:

MAIL_DRIVER=mail

There is no "mail" driver for laravel's mailing service (Laravel 5.5), you could have problems with the "smtp" because of wrong credentials. I think Laravel 5.2 might be using php's built-in "mail()" function when the "mail" driver is set, which could work on some shared hosting and fail on other.

Laravel 的邮件服务(Laravel 5.5)没有“邮件”驱动程序,由于凭据错误,您可能会遇到“smtp”问题。我认为 Laravel 5.2 可能在设置“邮件”驱动程序时使用了 php 的内置“mail()”函数,这可能会在某些共享主机上运行而在其他主机上失败。

Most shared hosting providers allow sending via the default server "sendmail" so you could also try this :

大多数共享主机提供商允许通过默认服务器“sendmail”发送,因此您也可以尝试以下操作:

MAIL_DRIVER=sendmail

If you can't get "sendmail" or "smtp" to work, you could try the "mailgun" or any other external mail service provider. Mailgun for example gives you 10 000 free mails per month so you will not need any paid subscriptions and the set-up tutorials are very easy, plus you have great tools for monitoring the sent mails.

如果您无法使用“sendmail”或“smtp”,您可以尝试使用“mailgun”或任何其他外部邮件服务提供商。例如,Mailgun 每月为您提供 10 000 封免费邮件,因此您不需要任何付费订阅,并且设置教程非常简单,此外您还有用于监控已发送邮件的出色工具。