Reputation: 611
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
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
Reputation: 4531
What worked for me is selecting 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
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
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
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
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
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
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.
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
Reputation: 141
If you use postfix, do this :
nano /etc/postfix/main.cf
# mydestination = ...
mydestination =
/etc/init.d/postfix reload
Upvotes: 13
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
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
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
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
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
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
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
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
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