DisgruntledGoat
DisgruntledGoat

Reputation: 72580

Reasons why PHP mail might not be working

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?

Upvotes: 1

Views: 1545

Answers (9)

Lukas C
Lukas C

Reputation: 453

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

Upvotes: 0

perrohunter
perrohunter

Reputation: 3546

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

Upvotes: 2

Julien
Julien

Reputation: 5779

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?

Upvotes: 0

da5id
da5id

Reputation: 9146

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.

Upvotes: 1

Spencer Ruport
Spencer Ruport

Reputation: 35117

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

Upvotes: 0

Erick
Erick

Reputation: 6089

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

Upvotes: 0

user36457
user36457

Reputation:

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.

Upvotes: 2

gnud
gnud

Reputation: 78628

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.

Upvotes: 0

Frank Crook
Frank Crook

Reputation: 1466

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.

Upvotes: 1

Related Questions