Home » Php » php – can't send email to addresses at my own domain

php – can't send email to addresses at my own domain

Posted by: admin April 23, 2020 Leave a comment

Questions:

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?

How to&Answers:

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.

Answer:

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

Answer:

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

Answer:

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.

Answer:

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]");

Answer:

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

Answer:

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.

Answer:

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.

Answer:

With PostFix, Debian7, smtp Mailjet

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

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

to

mydestination = localhost, localhost.localdomain, localhost

Answer:

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

Answer:

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]”.

Answer:

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.

Answer:

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.

Answer:

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

Answer:

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

Answer:

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 .

Answer:

SMTP mail server could be an option too.

Answer:

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

Answer:

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]