简体   繁体   English

无法向我自己域中的地址发送电子邮件

[英]can't send email to addresses at my own domain

I have a simple php script on my domain that sends me an email:我的域上有一个简单的 php 脚本,它会向我发送一封电子邮件:

...
$toMail = "me@gmail.com"; //this works - I get the email at my gmail
$toMail = "me@mydomain.com"; //this doesn't - I get nothing

mail($toMail, $subject, $message, $header); 

What setting to I change to fix this?我改变什么设置来解决这个问题?

For the people using Google Apps for email, but having your host in other provider this are more detailed instructions for the people that is not very familiar with cPanel.对于使用 Google Apps 发送电子邮件但您的主机位于其他提供商的人来说,这是对不太熟悉 cPanel 的人的更详细说明。

I could fix the problem of sending email from my domain using a PHP form, when sending the email to an account inside my domain.在将电子邮件发送到我的域内的帐户时,我可以解决使用 PHP 表单从我的域发送电子邮件的问题。

ie mydomain.example Contact form sending email to contact@mydomain.example .mydomain.example联系表格发送电子邮件到contact@mydomain.example The above was not working even if my domain has the correct MX records for the domain using Google Apps.即使我的域具有使用 Google Apps 的域的正确 MX 记录,上述操作也不起作用。

As Mike noted (and others) above the problem was solved: Adding the MX records into the cPanel.正如迈克(和其他人)在上面提到的那样,问题已经解决了:将 MX 记录添加到 cPanel 中。

  1. Enter into the cPanel进入cPanel
  2. Go the the cPanel Mail section转到 cPanel 邮件部分
  3. Search for MX Entry Maintenance, sometimes there is no text above the icon.搜索MX Entry Maintenance,有时图标上方没有文字。
  4. Select the related domain选择相关域
  5. Change Email Routing to Remote Mail Exchanger.电子邮件路由更改为远程邮件交换器。
  6. Add all the Google MX records as they are in your domain configuration using the appropriate priority values.使用适当的优先级值添加所有 Google MX 记录,因为它们在您的域配置中。 You can check the records here and priorities https://support.google.com/a/answer/174125您可以在此处查看记录和优先级https://support.google.com/a/answer/174125
  7. Double check that Remote Mail Exchanger.仔细检查远程邮件交换器。 is selected.被选中。

With this setting I was able to send email using mail PHP function to an email account inside the same domain as my website.通过此设置,我可以使用邮件 PHP 函数将电子邮件发送到与我的网站位于同一域内的电子邮件帐户。

Google App instructions talking about MX records https://support.google.com/a/answer/54717?hl=en关于 MX 记录的 Google 应用说明https://support.google.com/a/answer/54717?hl=en

I've had this problem myself, when I was redesigning a site recently.当我最近重新设计一个网站时,我自己也遇到了这个问题。

There was an issue with the way our system was set up, so that the system thought that because the email was coming from the same domain it was a spam email and as such blocked it.我们的系统设置方式存在问题,因此系统认为因为电子邮件来自同一个域,所以它是垃圾邮件,因此阻止了它。

Check with your system administrator that you are allowed to be sending the emails etc.请与您的系统管理员确认您是否可以发送电子邮件等。

Either that, or you'll have to modify the headers to have look like it's being sent from an external address.要么,要么您必须修改标头以使其看起来像是从外部地址发送的。 Hope you get it sorted.希望你能把它整理好。

If you use postfix , do this :如果您使用后缀,请执行以下操作:

  1. connect to your server via ssh.通过 ssh 连接到您的服务器。
  2. edit your main.cf file :编辑你的main.cf文件:

nano /etc/postfix/main.cf

  1. comment the following line with # :#注释以下行:

# mydestination = ...

  1. add at the end of the main.cf document :main.cf文件末尾添加:

mydestination =

  1. reload your postfix configuration by running :通过运行重新加载您的后缀配置:

/etc/init.d/postfix reload

The top answer at https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail seems correct to me. https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail的最佳答案对我来说似乎是正确的。 The gist of it is that you want the following in your sendmail.mc:它的要点是您希望在 sendmail.mc 中包含以下内容:

define(`MAIL_HUB`, 'example.com.')dnl
define(`LOCAL_RELAY`, 'example.com.')dnl

Where example.com is the domain in question.其中example.com是有问题的域。

You need to set an additional parameter on your mail function.您需要在邮件功能上设置一个附加参数。 On your working example you would need to prepend your email address with '-f' eg在您的工作示例中,您需要在您的电子邮件地址前面加上“-f”,例如

mail($toMail, $subject, $message, $header, "-fme@mydomain.example");

I had the same problem and was able to solve it in the following way.我遇到了同样的问题,并且能够通过以下方式解决它。 I do not store mail locally on the server but use MX records on the registrar to direct mail into Google Apps.我不在服务器上本地存储邮件,而是使用注册器上的 MX 记录将邮件定向到 Google Apps。 It turned out the MX records needed to be updated in Cpanel as well, as the server was not taking the MX records from the registrar but instead discarding since there was no local MX record or mailbox.事实证明,MX 记录也需要在 Cpanel 中更新,因为服务器没有从注册商那里获取 MX 记录,而是因为没有本地 MX 记录或邮箱而丢弃。 I updated the MX entries on Cpanel to match the registrar's MX entries, and the problem was fixed instantly我更新了 Cpanel 上的 MX 条目以匹配注册商的 MX 条目,问题立即得到解决

Do you have your email hosted on a different server than the website?您是否将电子邮件托管在与网站不同的服务器上? If that is the case the PHP script may be trying to send it internally in which case it'll just disappear, while the other target emails will get put on to the internet and routed properly.如果是这种情况,PHP 脚本可能会尝试在内部发送它,在这种情况下它会消失,而其他目标电子邮件将被放到互联网上并正确路由。

The solution I found was to disable the mail server on your web host, and then PHP will put the message on to the internet to be sent properly.我找到的解决方案是禁用您的网络主机上的邮件服务器,然后 PHP 会将邮件放到互联网上以便正确发送。

With PostFix, Debian7, smtp Mailjet使用 PostFix、Debian7、smtp Mailjet

If domain is my-domain.example , in /etc/postfix/main.cf , change如果域是my-domain.example ,在/etc/postfix/main.cf中,更改

mydestination = my-domain.example, localhost, localhost.localdomain, localhost

to

mydestination = localhost, localhost.localdomain, localhost

I agree with Michael Hellein, the root problem could be your sendmail considering your domain example.com email accounts as local accounts.我同意 Michael Hellein 的观点,根本问题可能是您的 sendmail 将您的域example.com电子邮件帐户视为本地帐户。 If so, here are few guiding links:如果是这样,这里有几个指导链接:

But in my case, using FreeBSD 8.2, what really did the trick was:但就我而言,使用 FreeBSD 8.2,真正的诀窍是:

# cd /etc/mail
# vim freebsd.mc

Add these two lines:添加这两行:

define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl

Right before:就在之前:

MAILER(local)
MAILER(smtp)

Then:然后:

# make

This is output:这是输出:

cp freebsd.mc host.example.com.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 host.example.com.mc > host.example.com.cf
cp freebsd.submit.mc host.example.com.submit.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 host.example.com.submit.mc > host.example.com.submit.cf

Then:然后:

# cp sendmail.cf sendmail.cf.bak
# cp host.example.com.cf sendmail.cf
# /etc/rc.d/sendmail restart

Hope this saves some headaches to someone.希望这可以为某人节省一些头痛。

确保您实际上可以将邮件发送到您的域电子邮件帐户,然后检查您的代码/电子邮件确保所有内容都拼写正确..如果这些都没有帮助,我不知道出了什么问题..

As explained by others, some servers are configured to reject emails missing a valid email address on the sending server.正如其他人所解释的,某些服务器被配置为拒绝发送服务器上缺少有效电子邮件地址的电子邮件。 Check that the $headers string includes a defined valid email address From:foo@example.com .检查$headers字符串是否包含已定义的有效电子邮件地址From:foo@example.com

I had a similar issue wherein all mails were being perfectly sent to other domains like gmail, live, yahoo etc but all mails would disappear on local domains.我有一个类似的问题,其中所有邮件都完美地发送到其他域,如 gmail、live、yahoo 等,但所有邮件都会在本地域中消失。 I had a VPS server with godaddy which was linux based running Qmail.我有一个带有 Godaddy 的 VPS 服务器,它是基于 linux 的运行 Qmail。

I solved the problem by removing the specific domain names in var/qmail/control/virtualdomains file .我通过删除 var/qmail/control/virtualdomains 文件中的特定域名解决了这个问题。

我遇到了同样的问题,由于我托管在另一台服务器上以接收电子邮件,我只需要禁用本地邮件服务器。

SMTP 邮件服务器也可以是一个选项。

I had this problem a few times, and the culprit was if the email was being hosted on another server (eg Google Apps).我有几次遇到这个问题,罪魁祸首是电子邮件是否托管在另一台服务器上(例如 Google Apps)。 When mail sends to the local domain, it doesn't bother doing a lookup on the MX record and therefore it will not get routed properly.当邮件发送到本地域时,它不会费心查找 MX 记录,因此不会正确路由。 The solution to this problem is just to simply have the mail function disabled on your server by your host.解决这个问题的方法就是简单地让您的主机在您的服务器上禁用邮件功能。

我在此错误上花费了 8 多个小时并解决了它,只需将标题更改为任何其他电子邮件地址即可

What worked for me is selecting Local Mail Exchanger :对我有用的是选择Local Mail Exchanger

  • Go to cPanel转到 cPanel
  • Select Email Routing选择电子邮件路由
  • Select your domain选择您的域
  • Select Local Mail Exchanger选择本地邮件交换器

Local Mail Exchanger will enable you to send an email to an account of the same domain in GoDaddy: eg: an email to info@yourdomain.example本地邮件交换器将使您能够向 GoDaddy 中相同域的帐户发送电子邮件:例如:发送电子邮件至info@yourdomain.example

I had this problem too.我也有这个问题。 Disabling the mail server meant no email at all was sent!禁用邮件服务器意味着根本没有发送任何电子邮件! So the fix I did was to remove all local domain names from the /etc/mail/local-host-names file所以我所做的修复是从/etc/mail/local-host-names文件中删除所有本地域名

Make sure your txt record is setup correctly for your domain.确保为您的域正确设置了txt记录。 This usually happens when you do not put this in the txt record: @ (None) v=spf1 include:_spf.google.com ~all这通常发生在您没有将其放入txt记录时: @ (None) v=spf1 include:_spf.google.com ~all

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM