PHP mail() 函数不会发送到 gmail,但会发送到我的非 gmail 帐户 [英] PHP mail() function will not send to gmail but will send to my non-gmail account

查看:37
本文介绍了PHP mail() 函数不会发送到 gmail,但会发送到我的非 gmail 帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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('myEmail@gmail.com', 'the subject', 'the message', 'From: webmaster@example.com', '-fwebmaster@example.com');
?>

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

when myEmail is a Gmail account, I never receive the message. However when I use a non-gmail account, I do receive 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

有什么想法吗?

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

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.

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

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

<?
$headers = 'From: <some@email.com>' . "
" .
'Reply-To: <some@email.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
'-fwebmaster@example.com');
?>

推荐答案

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

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

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

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.

代码:

$headers = 'From: <test@test.com>' . "
" .
'Reply-To: <test@test.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
  '-fwebmaster@example.com');
?>

感谢大家的帮助.

这篇关于PHP mail() 函数不会发送到 gmail,但会发送到我的非 gmail 帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆