0

I am working on a PHP script, which I have stripped down to just the emailing function for troubleshooting. My problem is that when I send the email to the desired address, it doesn't go through. However, if I switch the receiver address to my gmail account, it works perfectly. I have sent test emails to the desired address, which go through, and work perfectly.

Note that I have changed the email address below. This does not work.

$emailFrom = "sender@domain.com";
$emailTo = "receiver@domain.com" ;    
$emailSubject = "KMV - New Prints Order!";
$emailMessage = "Hello, World!";
$emailHeaders = 'From: '.$emailFrom."\r\n".
    'Reply-To: '.$emailFrom."\r\n" .
    'X-Mailer: PHP/' . phpversion();   

mail($emailTo, $emailSubject, $emailMessage, $emailHeaders); 

However if I change one line as follows:

$emailTo = "myAddress@gmail.com" ;

It works.

I'm lost as to what could be causing this issue.

cwhiii
  • 1,496
  • 2
  • 14
  • 16
  • 1
    Have you checked your junk folder? – Paul Stanley Oct 21 '15 at 20:31
  • I assume the From & To addresses are on the same domain? Are you also receiving email on the same server to that domain? So to say, your not using a 3rd party service for mail hosting, like office 360 or zoho? – Practically Oct 21 '15 at 20:31
  • 1
    I've found Gmail to be very liberal with accepting testing email from localhost. Other services are not as forgiving. Is `"sender@domain.com"` sending from a server that is authorized (via `domain.com`'s SPF record) to send on behalf of `domain.com`? (localhost is almost certainly **not**) – HPierce Oct 21 '15 at 20:44

1 Answers1

1

The problem is not in your PHP code. You have to debug your postfix or sendmail log in order to dig deeply into the problem. First check in your php.ini what is configured for ' sendmail_path = ' in order to figure out what service (daemon) you are using for sending emails (postfix, sendmail, etc...). Than find the appropriate log file of this service and analyze it further. Probably your messages are rejected at some point of the SMTP communication.

You can also configure an external mail service (one that is not running on your server and that you do not have to manage yourself) in your php.ini. If you are not going to send large amount of messages you can use gmail or yahoo. Here is a link howto set this up.

https://www.digitalocean.com/community/tutorials/how-to-use-gmail-or-yahoo-with-php-mail-function

If you want to send large amount of messages you have to consider using some sort of external service like mailchimp and mailgun or like office 360 and zoho as someone suggested in the comments above.

kpopovbg
  • 301
  • 1
  • 6