如果我不拥有 MX 记录,PHP mail() 函数是否可以工作

发布于 2024-07-04 19:31:09 字数 322 浏览 4 评论 0原文

我不确定我在这里使用了所有正确的术语,所以请原谅。

我刚刚建立了一个带有联系表单的网站,该表单使用 PHP mail() 函数发送电子邮件。 够简单的。 然而,实时站点实际上并不发送电子邮件,而是测试站点发送。 所以这不是我的代码。

它是一个共享主机,我们有另一个具有相同功能且运行良好的站点,因此它不是服务器。

两者之间的唯一区别是,不起作用的站点只有指向我们的名称服务器,因此 MX 记录永远不会触及我们的服务器。

所以我的问题是,请有人确认一下,如果我们没有指向我们服务器的 MX 记录,则 mail() 函数将无法工作。 谢谢

I'm not sure I'm using all the correct terminology here so be forgiving.

I just put up a site with a contact form that sends an email using the PHP mail() function. Simple enough. However the live site doesn't actually send the email, the test site does. So it's not my code.

It's a shared host and we have another site that has the same function that works perfectly, so it's not the server.

The only difference between the two is that the site that doesn't work just has the name server pointing to us and so the MX record never touches our server.

So my question is, could some one please confirm that the mail() function wont work if we don't have the MX record pointing to our server. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

记忆消瘦 2024-07-11 19:31:09

是的,您可以在“发件人”字段中输入您想要的任何内容,它仍然有效。

Yes, you could put in what ever you want in the 'from' field and it would still work.

仅此而已 2024-07-11 19:31:09

如果站点使用 SPF,请记住将发送站点包含在 SPF 记录中。 有关详细信息,请参阅此处

If the site uses SPF, remember to include the sending site in your SPF record. For more info see here.

予囚 2024-07-11 19:31:09

mail() 函数从托管脚本的服务器发送邮件。 由于许多共享托管提供商托管单独的邮件服务器,并且 mail() 函数不支持任何类型的身份验证,因此许多共享托管提供商会阻止它。

The mail() function sends mail from the server hosting the script. Since many shared hosting providers host separate mail servers, and because the mail() function doesn't support any sort of authentication, many shared hosting providers block it.

无需解释 2024-07-11 19:31:09

嘿伙计们,感谢您的回答,非常感谢。

在忽略这个问题几个月后,它再次出现,但我确实找到了问题的答案。

首先,正如您的回答所建议的,PHP 和 mail() 函数按预期工作。 邮件正在发送。

问题在于,当发送电子邮件时,它只是假设因为它是从 mydomain.com 发送到 *@mydomain.com 电子邮件,因此电子邮件本身托管在同一服务器上,因此它会发送到那里并忽略 MX 记录。

好吧,它比这更复杂一些,但这就是一般要点。

编辑:
找到该主题的更好版本 sendmail以及当邮件服务器不在网络主机上时的 MX 记录

Hey guys thanks for the answers, it is really appreciated.

After ignoring the issue for a few months it has come up again, I did however find the answer to my problems.

Firstly, as you answers suggested, PHP and the mail() function were working as expected. The mail was getting sent.

The problem lies when the email is sent, it simply presumes that because its being sent from mydomain.com to *@mydomain.com email that the email itself is hosted on the same server, so it gets sent there instead and ignores the MX record.

OK it's a bit more complicated than that, but that is the general jist.

Edit:
Found a better version of the topic sendmail and MX records when mail server is not on web host.

终陌 2024-07-11 19:31:09

有些主机(Godaddy 是最糟糕的)阻止您使用 sendmail 和 mail()。

我通常使用 smtp 从我的 php 应用程序发送电子邮件,并且使用 PHPMailer 这非常简单。 许多应用程序正在使用旧版本的 PHPMailer,有时更新它会有所帮助。 它也很容易快速添加到短脚本中。

Some hosts (Godaddy is the worst) block your use of sendmail and mail().

I generally use smtp to send emails from my php applications and with PHPMailer it's super easy. Many applications are using older versions of PHPMailer and sometimes updating it can help. It's also easy enough to add quickly to short scripts as well.

滥情空心 2024-07-11 19:31:09

是的。 它会工作得很好。 我有一个使用 mail() 函数的 PHP 脚本,并将 MX 记录设置为 Google Apps。

如果这两个脚本位于不同的主机上(您的帖子有点不清楚),那么请确保主机不会阻止某些自定义标头。 我在创建脚本时遇到了此问题,但删除除 From 标头之外的所有内容解决了问题。

Yes. It will work just fine. I have a PHP script using the mail() function with the MX records set to Google Apps.

If the two scripts are on different hosts (it's a bit unclear from your post), then make sure that the host doesn't block some of the custom headers. I had issues with this when creating my script, but removing all but the From header fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文