tags:

views:

524

answers:

9

I'm using the PHP mail() function to send email from a contact form. The function returns true so should be fine. But I'm not receiving the email.

I've seen posts that say you should always use the From and Reply-To headers in PHP mail to make sure it's delivered. I've tried various configs but nothing is working yet.

Is there any other way to debug the mail() function?

+1  A: 

Are you sending the mail from your own computer? You may not have set up a SMTP server that can access beyond your local domain. You may also be blocked by a spam filter, depending on your mail service.

If you're doing this from your own computer, test it by sending a local message to one of your local mail accounts (if you're using Linux, that is). If you think this is the problem, install postfix.

If you're doing it from a hosting service, check your spam folder.

Frank Crook
I'm sending it from my web site. And it's definitely not coming into my spam folder. I'll check with my host for any info.
DisgruntledGoat
*By "web site" I meant hosted online site, rather than my computer.
DisgruntledGoat
A: 

On Unix systems, mail() use sendmail, and there are many reasons (permissions, error in configuration) that this might fail. I'm not sure if PHP would detect and report all of these. Check any logs from sendmail.

You should also have a look at helpers for sending mail, from PEAR or Zend, for example.

gnud
+2  A: 

If you are on windows you will need to install an SMTP server.

If you are on linux you will need to enable sendmail and ensure the user account PHP is installed on has access to the sendmail binary.

Ask your host if your account has sufficient permissions to access the binary.

Posting your code here might also help in case it is an error in there you overlooked.

John T
A: 

On some servers you need to explicitely set the FROM header or it wont be sent.

Erick
A: 

Goat, if the server you're trying the function on is on a dynamic external IP you're SOL. Most mail servers block incoming connections on port 25 from dynamic IP ranges now. :(

Spencer Ruport
+1  A: 

I know it's not specifically answering your question, but my advice would be to use something like swiftmailer instead of mail(). It's much more reliable, both in terms of getting-it-to-work and getting-the-mail-through.

da5id
A: 

Is it a shared hosting? I know some companies override the mail function to avoid spam, and require additional arguments, or some predefined values (like the from field is required to be a valid address from your domain name). You might want to check with your web hosting company. Do you have a private set up where you could try the same code?

Julien
+2  A: 

Most of the time this problem is due to headers, the mail might get send but the SMTP server might never deliver it at all because of faulty headers

I'd suggest you to use a mailing class for PHP such as phpMailer which handles all of your problems with headers and has a really nice interface to use

cheers

PERR0_HUNTER
Thanks - I found independently that this is what Joomla uses so it can't be too bad. ;)
DisgruntledGoat
A: 

Your provider's mail server may be banned. Check dns blacklist or contact your hosting provider.

Lukas