sol
sol

Reputation: 611

can't send email to addresses at my own domain

I have a simple php script on my domain that sends me an email:

...
$toMail = "[email protected]"; //this works - I get the email at my gmail
$toMail = "[email protected]"; //this doesn't - I get nothing

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

What setting to I change to fix this?

Upvotes: 36

Views: 78782

Answers (19)

Michelle
Michelle

Reputation: 560

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:[email protected].

Upvotes: 0

edrian
edrian

Reputation: 4531

What worked for me is selecting Local Mail Exchanger:

  • Go to 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: e.g.: an email to [email protected]

Upvotes: 0

nezter
nezter

Reputation: 5

Make sure your txt record is setup correctly for your domain. This usually happens when you do not put this in the txt record: @ (None) v=spf1 include:_spf.google.com ~all

Upvotes: 0

estepix
estepix

Reputation: 81

I agree with Michael Hellein, the root problem could be your sendmail considering your domain example.com email accounts as local accounts. If so, here are few guiding links:

But in my case, using FreeBSD 8.2, what really did the trick was:

# 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.

Upvotes: 2

Nolwennig
Nolwennig

Reputation: 1684

With PostFix, Debian7, smtp Mailjet

If domain is my-domain.example, in /etc/postfix/main.cf, change

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

to

mydestination = localhost, localhost.localdomain, localhost

Upvotes: 1

David Pratt
David Pratt

Reputation: 723

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' e.g.

mail($toMail, $subject, $message, $header, "[email protected]");

Upvotes: 11

Michael Hellein
Michael Hellein

Reputation: 4588

The top answer at https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail seems correct to me. The gist of it is that you want the following in your sendmail.mc:

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

Where example.com is the domain in question.

Upvotes: 13

VicM
VicM

Reputation: 2479

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.

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.

i.e. mydomain.example Contact form sending email to [email protected]. The above was not working even if my domain has the correct MX records for the domain using Google Apps.

As Mike noted (and others) above the problem was solved: Adding the MX records into the cPanel.

  1. Enter into the cPanel
  2. Go the the cPanel Mail section
  3. Search for MX Entry Maintenance, sometimes there is no text above the icon.
  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. You can check the records here and priorities 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.

Google App instructions talking about MX records https://support.google.com/a/answer/54717?hl=en

Upvotes: 52

Stéphane Sabalot
Stéphane Sabalot

Reputation: 141

If you use postfix, do this :

  1. connect to your server via ssh.
  2. edit your main.cf file :

nano /etc/postfix/main.cf

  1. comment the following line with # :

# mydestination = ...

  1. add at the end of the main.cf document :

mydestination =

  1. reload your postfix configuration by running :

/etc/init.d/postfix reload

Upvotes: 13

Abdou Ghonim
Abdou Ghonim

Reputation: 29

I spend more than 8 hour on this error and solve it just change the header to any other email address and it will work

Upvotes: 0

user621639
user621639

Reputation:

SMTP mail server could be an option too.

Upvotes: 0

Sarthak  Gupta
Sarthak Gupta

Reputation: 654

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. I had a VPS server with godaddy which was linux based running Qmail.

I solved the problem by removing the specific domain names in var/qmail/control/virtualdomains file .

Upvotes: 0

schubySteve
schubySteve

Reputation: 727

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.

Upvotes: 23

Mike
Mike

Reputation: 31

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. 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. I updated the MX entries on Cpanel to match the registrar's MX entries, and the problem was fixed instantly

Upvotes: 3

Roberoo
Roberoo

Reputation: 9

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

Upvotes: 0

user258677
user258677

Reputation: 3

I had this problem a few times, and the culprit was if the email was being hosted on another server (e.g. 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. The solution to this problem is just to simply have the mail function disabled on your server by your host.

Upvotes: 0

user208320
user208320

Reputation:

I had the same issue, and since I was hosted on another server for e-mail, I just had to disable the local mail server.

Upvotes: 0

Meep3D
Meep3D

Reputation: 3756

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.

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.

Upvotes: 1

techy
techy

Reputation: 544

make sure you can actually send mail to your domain email account and then check your code/email make sure everything is spelled right.. if none of this helped i dont know what went wrong..

Upvotes: 0

Related Questions