PHP mail() 函数不会发送到 gmail,但会发送到我的非 gmail 帐户

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

PHP mail() function will not send to gmail but will send to my non-gmail account

phpemail

提问by ARH3

For some reason the php mail() function is not working properly on a site I am building. I tried to troubleshoot the issue down to its simplest form, and came up with this file:

由于某种原因,php mail() 函数在我正在构建的站点上无法正常工作。我试图将问题解决到最简单的形式,并想出了这个文件:

<?php
mail('[email protected]', 'the subject', 'the message', 'From: [email protected]', '[email protected]');
?>

when myEmail is a gmail account, I never recieve the message. However when I use a non-gmail account, I do recieve the message. I am at a loss and have tried everything to figure this out. I am starting to think it is an obscure host/server issue. You can see the server specs here: http://aopmfg.com/php.php

当 myEmail 是 Gmail 帐户时,我从未收到过邮件。但是,当我使用非 Gmail 帐户时,我确实收到了邮件。我不知所措,并已尽一切努力来解决这个问题。我开始认为这是一个不起眼的主机/服务器问题。您可以在此处查看服务器规格:http: //aopmfg.com/php.php

Any ideas?

有任何想法吗?

EDIT - let me also add that this was all working fine a few weeks ago, the last time I tested it. No significant code changes since then at all.

编辑 - 让我还要补充一点,几周前,这是我最后一次测试它时一切正常。从那时起根本没有重大的代码更改。

EDIT 2 - After reading a similar post I tried adding From and Reply-To headers... still no luck. New code:

编辑 2 - 在阅读了类似的帖子后,我尝试添加 From 和 Reply-To 标题......仍然没有运气。新代码:

<?
$headers = 'From: <[email protected]>' . "\r\n" .
'Reply-To: <[email protected]>';

mail('<[email protected]>', 'the subject', 'the message', $headers,
'[email protected]');
?>

回答by ARH3

It turns out that Google blocked my server because another site on the same server was hacked and used for spam.

事实证明,谷歌阻止了我的服务器,因为同一台服务器上的另一个站点被黑客入侵并用于垃圾邮件。

To test and ensure that it was a problem with the server, I created a simple PHP file that would send an email to my email address on page refresh. It worked when I sent to my exchange-based email address, but not to any Google-related accounts.

为了测试并确保它是服务器的问题,我创建了一个简单的 PHP 文件,它会在页面刷新时向我的电子邮件地址发送一封电子邮件。当我发送到我的基于交换的电子邮件地址时它起作用了,但没有发送到任何与 Google 相关的帐户。

Code:

代码:

$headers = 'From: <[email protected]>' . "\r\n" .
'Reply-To: <[email protected]>';

mail('<[email protected]>', 'the subject', 'the message', $headers,
  '[email protected]');
?>

Thanks for the help all.

感谢大家的帮助。

回答by Cassie Smith

Try putting <> around the From and Reply to addresses. I had that same problem with work emails.

尝试将 <> 放在 From 和 Reply to 地址周围。我的工作电子邮件也有同样的问题。

回答by Wim

I had a similar problem with gmail. However my subject title was "See if you have won". When I changed this to something less marketing/spammy, it came through. So it's not always the PHP code who is causing this, but it can be the subject title as well which is blacklisted.

我在 gmail 上遇到了类似的问题。然而,我的主题是“看看你是否赢了”。当我将其更改为不那么营销/垃圾邮件的内容时,它就通过了。因此,导致这种情况的并不总是 PHP 代码,但也可能是被列入黑名单的主题标题。

回答by Dharam Jindal

I was having the same problem. But when I checked my C:\xampp\mailoutput folder, the mail sent was received in this folder. Now please check and do the needful. It was sent in my testing local server. If it is sent on the real server, that may be on your hosting server and you have to check through site hoster

我遇到了同样的问题。但是当我检查我的 C:\xampp\mailoutput 文件夹时,发送的邮件是在这个文件夹中收到的。现在请检查并做必要的事情。它是在我的测试本地服务器中发送的。如果它是在真实服务器上发送的,那可能是在您的托管服务器上,您必须通过站点托管商进行检查