0

I am able to send emails from my Mercury mail server to my Gmail account, but when I try to it using the mail() function in PHP, it doesn't work! Why?

<?php
if(mail('XYZ@gmail.com','NICE','OK'))
{
echo "success";
}
?>

It shows "Success" in my browser but there's no mail in my mailbox.

Artaex
  • 5
  • 3
Harsh
  • 149
  • 3
  • 14
  • possible duplicate of [Send email using GMail SMTP server from PHP page](http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page) – Brad Mar 28 '12 at 16:49
  • Are you executing your script on your desktop computer? On a server? Did you check your spam folder? – grifos Mar 28 '12 at 16:50
  • I guess a mail without a specified sender will ALWAYS be considered spam. – m90 Mar 28 '12 at 16:52

3 Answers3

1

You cannot debug issues like this without having access to the logfile of the mail server you are using to send your email.

However, if it's a machine connected via dialup (i.e. one that is not in a datacenter) you are very unlikely to be able to send any emails to the big email providers as they are going to block your emails - usually only spam comes from MTAs running on dialup hosts.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • I think the assumption of dialup only applies to third world countries. Majority of the SP now allow mail protocol and is not blocked. I can tell you verizon does not block smtp. But good point to bring up, incase this person is from third world country – Churk Mar 28 '12 at 16:57
  • Well I didn't mean *actual* dialup but pretty much any home connections. Try connecting e.g. to a gmail or hotmail MTA using netcat/telnet and you can be pretty sure it rejects you before you even finished throwing a complete email at it. – ThiefMaster Mar 28 '12 at 19:40
0

have you check your spam filters? or is your mail server setup on php.ini? did u setup smtp authentication? documented by this: http://us3.php.net/manual/en/mail.setup.php

Churk
  • 4,556
  • 5
  • 22
  • 37
0

I had this same problem. It turned out that my smart-relay was missing in the mail configuration.